From 629c0620721c34178f9767dd4c57226563d15dcd Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 3 Jan 2014 10:40:00 +0100 Subject: [PATCH] removed ehcache --- pom.xml | 1 - scm-plugin-backend/pom.xml | 4 + scm-webapp/pom.xml | 8 - .../DefaultCacheConfigurationLoader.java | 8 +- .../main/java/sonia/scm/cache/EhCache.java | 210 --------- .../scm/cache/EhCacheConfigurationReader.java | 443 ------------------ .../java/sonia/scm/cache/EhCacheManager.java | 149 ------ .../java/sonia/scm/cache/CacheTestUtil.java | 11 - .../java/sonia/scm/cache/EhCacheCopyTest.java | 92 ---- .../sonia/scm/cache/EhCacheManagerTest.java | 85 ---- .../java/sonia/scm/cache/EhCacheTest.java | 54 --- .../scm/cache/EhConfigurationReaderTest.java | 342 -------------- 12 files changed, 8 insertions(+), 1399 deletions(-) delete mode 100644 scm-webapp/src/main/java/sonia/scm/cache/EhCache.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/cache/EhCacheManager.java delete mode 100644 scm-webapp/src/test/java/sonia/scm/cache/EhCacheCopyTest.java delete mode 100644 scm-webapp/src/test/java/sonia/scm/cache/EhCacheManagerTest.java delete mode 100644 scm-webapp/src/test/java/sonia/scm/cache/EhCacheTest.java delete mode 100644 scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java diff --git a/pom.xml b/pom.xml index c89245ca9a..f32078f9e1 100644 --- a/pom.xml +++ b/pom.xml @@ -422,7 +422,6 @@ 2.5 3.0 1.18 - 2.6.6 2.3.20 7.6.14.v20131031 diff --git a/scm-plugin-backend/pom.xml b/scm-plugin-backend/pom.xml index 90de9b0851..97487a169e 100644 --- a/scm-plugin-backend/pom.xml +++ b/scm-plugin-backend/pom.xml @@ -157,5 +157,9 @@ scm-plugin-backend + + + 2.6.6 + diff --git a/scm-webapp/pom.xml b/scm-webapp/pom.xml index b4a35602c0..811912bfe6 100644 --- a/scm-webapp/pom.xml +++ b/scm-webapp/pom.xml @@ -151,14 +151,6 @@ ${slf4j.version} - - - - net.sf.ehcache - ehcache-core - ${ehcache.version} - - diff --git a/scm-webapp/src/main/java/sonia/scm/cache/DefaultCacheConfigurationLoader.java b/scm-webapp/src/main/java/sonia/scm/cache/DefaultCacheConfigurationLoader.java index 4ec4a48c04..d23ae8607c 100644 --- a/scm-webapp/src/main/java/sonia/scm/cache/DefaultCacheConfigurationLoader.java +++ b/scm-webapp/src/main/java/sonia/scm/cache/DefaultCacheConfigurationLoader.java @@ -104,17 +104,17 @@ public class DefaultCacheConfigurationLoader implements CacheConfigurationLoader public Iterator 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; } diff --git a/scm-webapp/src/main/java/sonia/scm/cache/EhCache.java b/scm-webapp/src/main/java/sonia/scm/cache/EhCache.java deleted file mode 100644 index 4ac0e2a49e..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/cache/EhCache.java +++ /dev/null @@ -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 - * @param - */ -public class EhCache implements Cache -{ - - /** 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 filter) - { - boolean result = true; - Iterator 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; -} diff --git a/scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java b/scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java deleted file mode 100644 index 04b10ebcca..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java +++ /dev/null @@ -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 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 nodeMap = Maps.newLinkedHashMap(); - - /** Field description */ - private Map attributeMap = Maps.newLinkedHashMap(); -} diff --git a/scm-webapp/src/main/java/sonia/scm/cache/EhCacheManager.java b/scm-webapp/src/main/java/sonia/scm/cache/EhCacheManager.java deleted file mode 100644 index cc4b6e9b1f..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/cache/EhCacheManager.java +++ /dev/null @@ -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 - * @param - * - * @return - */ - @Override - public synchronized Cache getCache(Class key, Class 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(c, name); - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private net.sf.ehcache.CacheManager cacheManager; -} diff --git a/scm-webapp/src/test/java/sonia/scm/cache/CacheTestUtil.java b/scm-webapp/src/test/java/sonia/scm/cache/CacheTestUtil.java index 7900f67320..042bcac112 100644 --- a/scm-webapp/src/test/java/sonia/scm/cache/CacheTestUtil.java +++ b/scm-webapp/src/test/java/sonia/scm/cache/CacheTestUtil.java @@ -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 * diff --git a/scm-webapp/src/test/java/sonia/scm/cache/EhCacheCopyTest.java b/scm-webapp/src/test/java/sonia/scm/cache/EhCacheCopyTest.java deleted file mode 100644 index 5a2077657a..0000000000 --- a/scm-webapp/src/test/java/sonia/scm/cache/EhCacheCopyTest.java +++ /dev/null @@ -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 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(c, "c1"); - } -} diff --git a/scm-webapp/src/test/java/sonia/scm/cache/EhCacheManagerTest.java b/scm-webapp/src/test/java/sonia/scm/cache/EhCacheManagerTest.java deleted file mode 100644 index d2139de0df..0000000000 --- a/scm-webapp/src/test/java/sonia/scm/cache/EhCacheManagerTest.java +++ /dev/null @@ -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(); - } -} diff --git a/scm-webapp/src/test/java/sonia/scm/cache/EhCacheTest.java b/scm-webapp/src/test/java/sonia/scm/cache/EhCacheTest.java deleted file mode 100644 index 4dc349a3d7..0000000000 --- a/scm-webapp/src/test/java/sonia/scm/cache/EhCacheTest.java +++ /dev/null @@ -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(); - } -} diff --git a/scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java b/scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java deleted file mode 100644 index 67f4c332b2..0000000000 --- a/scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java +++ /dev/null @@ -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 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 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(); -}