mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-06 07:28:39 +02:00
removed ehcache
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -422,7 +422,6 @@
|
||||
<servlet.version>2.5</servlet.version>
|
||||
<guice.version>3.0</guice.version>
|
||||
<jersey.version>1.18</jersey.version>
|
||||
<ehcache.version>2.6.6</ehcache.version>
|
||||
<freemarker.version>2.3.20</freemarker.version>
|
||||
<jetty.version>7.6.14.v20131031</jetty.version>
|
||||
|
||||
|
||||
@@ -157,5 +157,9 @@
|
||||
|
||||
<finalName>scm-plugin-backend</finalName>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<ehcache.version>2.6.6</ehcache.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -151,14 +151,6 @@
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- cache -->
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
<artifactId>ehcache-core</artifactId>
|
||||
<version>${ehcache.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- only for BeanComparator, replace with own implementation -->
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -104,17 +104,17 @@ public class DefaultCacheConfigurationLoader implements CacheConfigurationLoader
|
||||
public Iterator<URL> getModuleResources()
|
||||
{
|
||||
return CacheConfigurations.findModuleResources(
|
||||
EhCacheConfigurationReader.class, moduleResources);
|
||||
DefaultCacheConfigurationLoader.class, moduleResources);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String defaultResource;
|
||||
private final String defaultResource;
|
||||
|
||||
/** Field description */
|
||||
private String manualFileResource;
|
||||
private final String manualFileResource;
|
||||
|
||||
/** Field description */
|
||||
private String moduleResources;
|
||||
private final String moduleResources;
|
||||
}
|
||||
|
||||
@@ -1,210 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.Filter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
public class EhCache<K, V> implements Cache<K, V>
|
||||
{
|
||||
|
||||
/** the logger for EhCache */
|
||||
private static final Logger logger = LoggerFactory.getLogger(EhCache.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param cache
|
||||
* @param name
|
||||
*/
|
||||
public EhCache(net.sf.ehcache.Cache cache, String name)
|
||||
{
|
||||
this.cache = cache;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("clear cache {}", name);
|
||||
}
|
||||
|
||||
cache.removeAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(K key)
|
||||
{
|
||||
return cache.get(key) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
@Override
|
||||
public void put(K key, V value)
|
||||
{
|
||||
cache.put(new Element(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean remove(K key)
|
||||
{
|
||||
return cache.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param filter
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAll(Filter<K> filter)
|
||||
{
|
||||
boolean result = true;
|
||||
Iterator<K> it = cache.getKeys().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
K key = it.next();
|
||||
|
||||
if (filter.accept(key))
|
||||
{
|
||||
if (!cache.remove(key))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public V get(K key)
|
||||
{
|
||||
V value = null;
|
||||
Element el = cache.get(key);
|
||||
|
||||
if (el != null)
|
||||
{
|
||||
value = (V) el.getObjectValue();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@VisibleForTesting
|
||||
net.sf.ehcache.Cache getCacheImplementation()
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private net.sf.ehcache.Cache cache;
|
||||
|
||||
/** Field description */
|
||||
private String name;
|
||||
}
|
||||
@@ -1,443 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class EhCacheConfigurationReader
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final String ATTRIBUTE_NAME = "name";
|
||||
|
||||
/** Field description */
|
||||
private static final String DEFAULT = "/config/ehcache.xml";
|
||||
|
||||
/** Field description */
|
||||
private static final String MANUAL_RESOURCE =
|
||||
"ext".concat(File.separator).concat("ehcache.xml");
|
||||
|
||||
/** Field description */
|
||||
private static final String MODULE_RESOURCES = "META-INF/scm/ehcache.xml";
|
||||
|
||||
/**
|
||||
* the logger for EhCacheConfigurationReader
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(EhCacheConfigurationReader.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param loader
|
||||
*/
|
||||
@VisibleForTesting
|
||||
EhCacheConfigurationReader(CacheConfigurationLoader loader)
|
||||
{
|
||||
this.loader = loader;
|
||||
|
||||
try
|
||||
{
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
}
|
||||
catch (ParserConfigurationException ex)
|
||||
{
|
||||
throw new RuntimeException("could not create document builder", ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
public static InputStream read(){
|
||||
return new EhCacheConfigurationReader(new DefaultCacheConfigurationLoader(
|
||||
DEFAULT, MANUAL_RESOURCE, MODULE_RESOURCES)).doRead();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@VisibleForTesting
|
||||
InputStream doRead()
|
||||
{
|
||||
URL defaultConfig = loader.getDefaultResource();
|
||||
|
||||
if (defaultConfig == null)
|
||||
{
|
||||
throw new IllegalStateException(
|
||||
"could not find default cache configuration");
|
||||
}
|
||||
|
||||
readConfiguration(defaultConfig, true);
|
||||
|
||||
Iterator<URL> it = loader.getModuleResources();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
readConfiguration(it.next(), false);
|
||||
}
|
||||
|
||||
File manualFile = loader.getManualFileResource();
|
||||
|
||||
if (manualFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
readConfiguration(manualFile.toURI().toURL(), false);
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
logger.error("malformed url", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("could not find manual configuration at {}", manualFile);
|
||||
}
|
||||
|
||||
Document doc = createMergedConfiguration();
|
||||
|
||||
return createInputStream(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param doc
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private InputStream createInputStream(Document doc)
|
||||
{
|
||||
InputStream stream;
|
||||
Transformer transformer;
|
||||
|
||||
try
|
||||
{
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
transformer.transform(new DOMSource(doc), new StreamResult(baos));
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("effective ehcache configuration: {}", baos.toString());
|
||||
}
|
||||
|
||||
stream = new ByteArrayInputStream(baos.toByteArray());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new IllegalStateException("could not create transformer", ex);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Document createMergedConfiguration()
|
||||
{
|
||||
Document merged = builder.newDocument();
|
||||
|
||||
Element rootEl = merged.createElementNS("http://ehcache.org/ehcache.xsd",
|
||||
"ehcache");
|
||||
|
||||
for (Attr attribute : attributeMap.values())
|
||||
{
|
||||
Attr mergedAttr = (Attr) merged.adoptNode(attribute);
|
||||
|
||||
rootEl.setAttributeNode(mergedAttr);
|
||||
}
|
||||
|
||||
for (Node node : nodeMap.values())
|
||||
{
|
||||
Node mergedNode = merged.adoptNode(node);
|
||||
|
||||
rootEl.appendChild(mergedNode);
|
||||
}
|
||||
|
||||
merged.appendChild(rootEl);
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param throwException
|
||||
*/
|
||||
private void readConfiguration(URL url, boolean throwException)
|
||||
{
|
||||
logger.debug("read cache configuration from url {}", url.toExternalForm());
|
||||
|
||||
InputStream stream = null;
|
||||
|
||||
try
|
||||
{
|
||||
stream = url.openStream();
|
||||
|
||||
Document document = builder.parse(stream);
|
||||
Element rootEl = document.getDocumentElement();
|
||||
|
||||
readConfiguration(rootEl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (throwException)
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"could not read configuration at ".concat(url.toExternalForm()), ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("could not read configuration at {}", url.toExternalForm());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Closeables.closeQuietly(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param rootEl
|
||||
*/
|
||||
private void readConfiguration(Element rootEl)
|
||||
{
|
||||
NamedNodeMap attributes = rootEl.getAttributes();
|
||||
|
||||
for (int i = 0; i < attributes.getLength(); i++)
|
||||
{
|
||||
Node node = attributes.item(i);
|
||||
|
||||
if (Node.ATTRIBUTE_NODE == node.getNodeType())
|
||||
{
|
||||
String name = node.getNodeName();
|
||||
|
||||
if (!name.startsWith("xmlns") && (node instanceof Attr))
|
||||
{
|
||||
attributeMap.put(node.getNodeName(), (Attr) node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NodeList list = rootEl.getChildNodes();
|
||||
|
||||
for (int i = 0; i < list.getLength(); i++)
|
||||
{
|
||||
Node node = list.item(i);
|
||||
|
||||
if (Node.ELEMENT_NODE == node.getNodeType())
|
||||
{
|
||||
String element = node.getNodeName();
|
||||
String name = null;
|
||||
Node nameNode = node.getAttributes().getNamedItem(ATTRIBUTE_NAME);
|
||||
|
||||
if (nameNode != null)
|
||||
{
|
||||
name = nameNode.getNodeValue();
|
||||
}
|
||||
|
||||
nodeMap.put(new Id(element, name), node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class description
|
||||
*
|
||||
*
|
||||
* @version Enter version here..., 13/03/19
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class Id
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param element
|
||||
* @param name
|
||||
*/
|
||||
public Id(String element, String name)
|
||||
{
|
||||
this.element = element;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//~--- methods ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param obj
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Id other = (Id) obj;
|
||||
|
||||
return Objects.equal(element, other.element)
|
||||
&& Objects.equal(name, other.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(element, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
||||
//J-
|
||||
return Objects.toStringHelper(this)
|
||||
.add("element", element)
|
||||
.add("name", name)
|
||||
.toString();
|
||||
//J+
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String element;
|
||||
|
||||
/** Field description */
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private DocumentBuilder builder;
|
||||
|
||||
/** Field description */
|
||||
private CacheConfigurationLoader loader;
|
||||
|
||||
/** Field description */
|
||||
private Map<Id, Node> nodeMap = Maps.newLinkedHashMap();
|
||||
|
||||
/** Field description */
|
||||
private Map<String, Attr> attributeMap = Maps.newLinkedHashMap();
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class EhCacheManager implements CacheManager
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String CONFIG = "/config/ehcache.xml";
|
||||
|
||||
/** the logger for EhCacheManager */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(EhCacheManager.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public EhCacheManager()
|
||||
{
|
||||
|
||||
InputStream stream = null;
|
||||
|
||||
try
|
||||
{
|
||||
stream = EhCacheConfigurationReader.read();
|
||||
cacheManager = new net.sf.ehcache.CacheManager(stream);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Closeables.closeQuietly(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is only for unit tests
|
||||
*
|
||||
*
|
||||
* @param cacheManager
|
||||
*/
|
||||
public EhCacheManager(net.sf.ehcache.CacheManager cacheManager)
|
||||
{
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
cacheManager.shutdown();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param name
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public synchronized <K, V> Cache<K, V> getCache(Class<K> key, Class<V> value,
|
||||
String name)
|
||||
{
|
||||
net.sf.ehcache.Cache c = cacheManager.getCache(name);
|
||||
|
||||
if (c == null)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("could not find cache {}, create new from defaults", name);
|
||||
}
|
||||
|
||||
cacheManager.addCacheIfAbsent(name);
|
||||
c = cacheManager.getCache(name);
|
||||
}
|
||||
|
||||
return new EhCache<K, V>(c, name);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private net.sf.ehcache.CacheManager cacheManager;
|
||||
}
|
||||
@@ -51,17 +51,6 @@ public final class CacheTestUtil
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static EhCacheManager createDefaultEhCacheManager()
|
||||
{
|
||||
return new EhCacheManager(net.sf.ehcache.CacheManager.create());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
|
||||
import sonia.scm.cache.CacheCopyTestBase.MutableObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class EhCacheCopyTest extends CacheCopyTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param strategy
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Cache<String, MutableObject> createCache(CopyStrategy strategy)
|
||||
{
|
||||
net.sf.ehcache.CacheManager cm = net.sf.ehcache.CacheManager.create();
|
||||
|
||||
if (cm.cacheExists("c1"))
|
||||
{
|
||||
cm.removeCache("c1");
|
||||
}
|
||||
|
||||
CacheConfiguration cc = new CacheConfiguration("c1", 100);
|
||||
|
||||
switch (strategy)
|
||||
{
|
||||
case READ :
|
||||
cc.setCopyOnRead(true);
|
||||
|
||||
break;
|
||||
|
||||
case WRITE :
|
||||
cc.setCopyOnWrite(true);
|
||||
|
||||
break;
|
||||
|
||||
case READWRITE :
|
||||
cc.setCopyOnRead(true);
|
||||
cc.setCopyOnWrite(true);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
net.sf.ehcache.Cache c = new net.sf.ehcache.Cache(cc);
|
||||
cm.addCache(c);
|
||||
return new EhCache<String, MutableObject>(c, "c1");
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class EhCacheManagerTest extends CacheManagerTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param c1
|
||||
* @param c2
|
||||
*/
|
||||
@Override
|
||||
protected void assertIsSame(Cache c1, Cache c2)
|
||||
{
|
||||
Assert.assertSame(getCacheImplementation(c1), getCacheImplementation(c1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected CacheManager createCacheManager()
|
||||
{
|
||||
return CacheTestUtil.createDefaultEhCacheManager();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param c1
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private net.sf.ehcache.Cache getCacheImplementation(Cache c1)
|
||||
{
|
||||
return ((EhCache) c1).getCacheImplementation();
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class EhCacheTest extends CacheTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected CacheManager createCacheManager()
|
||||
{
|
||||
return CacheTestUtil.createDefaultEhCacheManager();
|
||||
}
|
||||
}
|
||||
@@ -1,342 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.config.ConfigurationFactory;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class EhConfigurationReaderTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testDefaultConfiguration()
|
||||
{
|
||||
EhCacheConfigurationReader reader = createReader("ehcache.001.xml");
|
||||
Configuration c = createConfiguration(reader);
|
||||
|
||||
checkDefaultConfiguration(c);
|
||||
checkCacheConfiguration(c, "sonia.test.cache.001", 1000l, 30l, 60l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGlobalAttributes()
|
||||
{
|
||||
EhCacheConfigurationReader reader = createReader("ehcache.006.xml");
|
||||
Configuration c = createConfiguration(reader);
|
||||
|
||||
assertFalse(c.getUpdateCheck());
|
||||
assertEquals("512M", c.getMaxBytesLocalDiskAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMergeAndOverride()
|
||||
{
|
||||
//J-
|
||||
EhCacheConfigurationReader reader = createReader(
|
||||
"ehcache.001.xml",
|
||||
Iterators.forArray("ehcache.002.xml", "ehcache.003.xml"),
|
||||
"ehcache.004.xml"
|
||||
);
|
||||
//J+
|
||||
|
||||
Configuration c = createConfiguration(reader);
|
||||
|
||||
// cache sonia.test.cache.001 override by cache.004.xml
|
||||
checkCacheConfiguration(c, "sonia.test.cache.001", 6l, 2l, 8l);
|
||||
checkCacheConfiguration(c, "sonia.test.cache.002", 2000l, 60l, 120l);
|
||||
checkCacheConfiguration(c, "sonia.test.cache.003", 3000l, 120l, 2400l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMergeWithManualConfiguration()
|
||||
{
|
||||
EhCacheConfigurationReader reader = createReader("ehcache.001.xml", null,
|
||||
"ehcache.002.xml");
|
||||
|
||||
Configuration c = createConfiguration(reader);
|
||||
|
||||
checkDefaultConfiguration(c);
|
||||
|
||||
checkCacheConfiguration(c, "sonia.test.cache.001", 1000l, 30l, 60l);
|
||||
checkCacheConfiguration(c, "sonia.test.cache.002", 2000l, 60l, 120l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testMergeWithModuleConfigurations()
|
||||
{
|
||||
EhCacheConfigurationReader reader = createReader("ehcache.001.xml",
|
||||
Iterators.forArray("ehcache.002.xml",
|
||||
"ehcache.003.xml"));
|
||||
|
||||
Configuration c = createConfiguration(reader);
|
||||
|
||||
checkDefaultConfiguration(c);
|
||||
|
||||
checkCacheConfiguration(c, "sonia.test.cache.001", 1000l, 30l, 60l);
|
||||
checkCacheConfiguration(c, "sonia.test.cache.002", 2000l, 60l, 120l);
|
||||
checkCacheConfiguration(c, "sonia.test.cache.003", 3000l, 120l, 2400l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testMissingDefaultConfiguration()
|
||||
{
|
||||
EhCacheConfigurationReader reader = createReader();
|
||||
|
||||
reader.doRead();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testOverrideDefaultConfiguration()
|
||||
{
|
||||
//J-
|
||||
EhCacheConfigurationReader reader = createReader(
|
||||
"ehcache.001.xml",
|
||||
Iterators.forArray("ehcache.005.xml")
|
||||
);
|
||||
//J+
|
||||
Configuration c = createConfiguration(reader);
|
||||
|
||||
checkDefaultConfiguration(c, 170l, 18900l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testOverrideGlobalAttributes()
|
||||
{
|
||||
EhCacheConfigurationReader reader = createReader("ehcache.006.xml", null,
|
||||
"ehcache.007.xml");
|
||||
Configuration c = createConfiguration(reader);
|
||||
|
||||
assertTrue(c.getUpdateCheck());
|
||||
assertEquals("1G", c.getMaxBytesLocalDiskAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param c
|
||||
* @param name
|
||||
* @param maxEntriesLocalHeap
|
||||
* @param timeToIdleSeconds
|
||||
* @param timeToLiveSeconds
|
||||
*/
|
||||
private void checkCacheConfiguration(Configuration c, String name,
|
||||
long maxEntriesLocalHeap, long timeToIdleSeconds, long timeToLiveSeconds)
|
||||
{
|
||||
CacheConfiguration cc = c.getCacheConfigurations().get(name);
|
||||
|
||||
assertNotNull(cc);
|
||||
assertEquals(maxEntriesLocalHeap, cc.getMaxEntriesLocalHeap());
|
||||
assertEquals(timeToIdleSeconds, cc.getTimeToIdleSeconds());
|
||||
assertEquals(timeToLiveSeconds, cc.getTimeToLiveSeconds());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
private void checkDefaultConfiguration(Configuration c)
|
||||
{
|
||||
checkDefaultConfiguration(c, 100l, 10000l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param c
|
||||
* @param maxEntriesLocalHeap
|
||||
* @param maxEntriesLocalDisk
|
||||
*/
|
||||
private void checkDefaultConfiguration(Configuration c,
|
||||
long maxEntriesLocalHeap, long maxEntriesLocalDisk)
|
||||
{
|
||||
CacheConfiguration dcc = c.getDefaultCacheConfiguration();
|
||||
|
||||
assertNotNull(dcc);
|
||||
assertEquals(maxEntriesLocalHeap, dcc.getMaxEntriesLocalHeap());
|
||||
assertEquals(maxEntriesLocalDisk, dcc.getMaxEntriesLocalDisk());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param reader
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Configuration createConfiguration(EhCacheConfigurationReader reader)
|
||||
{
|
||||
Configuration config = null;
|
||||
InputStream content = null;
|
||||
|
||||
try
|
||||
{
|
||||
content = reader.doRead();
|
||||
config = ConfigurationFactory.parseConfiguration(content);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Closeables.closeQuietly(content);
|
||||
}
|
||||
|
||||
assertNotNull(config);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param defaultConfiguration
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private EhCacheConfigurationReader createReader(String defaultConfiguration)
|
||||
{
|
||||
return new EhCacheConfigurationReader(
|
||||
new CacheConfigurationTestLoader(tempFolder, defaultConfiguration));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param defaultConfiguration
|
||||
* @param moduleConfiguration
|
||||
* @param manualConfiguration
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private EhCacheConfigurationReader createReader(String defaultConfiguration,
|
||||
Iterator<String> moduleConfiguration, String manualConfiguration)
|
||||
{
|
||||
return new EhCacheConfigurationReader(
|
||||
new CacheConfigurationTestLoader(
|
||||
tempFolder, defaultConfiguration, moduleConfiguration,
|
||||
manualConfiguration));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param defaultConfiguration
|
||||
* @param moduleConfiguration
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private EhCacheConfigurationReader createReader(String defaultConfiguration,
|
||||
Iterator<String> moduleConfiguration)
|
||||
{
|
||||
return new EhCacheConfigurationReader(
|
||||
new CacheConfigurationTestLoader(
|
||||
tempFolder, defaultConfiguration, moduleConfiguration));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private EhCacheConfigurationReader createReader()
|
||||
{
|
||||
return new EhCacheConfigurationReader(
|
||||
new CacheConfigurationTestLoader(tempFolder));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
}
|
||||
Reference in New Issue
Block a user