removed ehcache

This commit is contained in:
Sebastian Sdorra
2014-01-03 10:40:00 +01:00
parent aec7773239
commit 629c062072
12 changed files with 8 additions and 1399 deletions

View File

@@ -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
*

View File

@@ -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");
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}