general revision of cache package; added ConcurrentMapCacheManager

This commit is contained in:
Juergen Hoeller
2011-07-22 09:32:56 +00:00
parent 02362f4347
commit abdae3d26b
46 changed files with 933 additions and 728 deletions

View File

@@ -24,7 +24,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.cache.support.NoOpCacheManager;
public class NoOpCacheManagerTest {
public class NoOpCacheManagerTests {
private CacheManager manager;

View File

@@ -20,16 +20,16 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.springframework.cache.Cache;
import org.springframework.cache.vendor.AbstractNativeCacheTest;
import org.springframework.cache.vendor.AbstractNativeCacheTests;
/**
* @author Costin Leau
*/
public class ConcurrentCacheTest extends AbstractNativeCacheTest<ConcurrentMap<Object, Object>> {
public class ConcurrentCacheTests extends AbstractNativeCacheTests<ConcurrentMap<Object, Object>> {
@Override
protected Cache createCache(ConcurrentMap<Object, Object> nativeCache) {
return new ConcurrentMapCache(nativeCache, CACHE_NAME, true);
return new ConcurrentMapCache(CACHE_NAME, nativeCache, true);
}
@Override

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.concurrent;
import org.junit.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
*/
public class ConcurrentMapCacheManagerTests {
@Test
public void testDynamicMode() {
CacheManager cm = new ConcurrentMapCacheManager();
Cache cache1 = cm.getCache("c1");
assertTrue(cache1 instanceof ConcurrentMapCache);
Cache cache1again = cm.getCache("c1");
assertSame(cache1again, cache1);
Cache cache2 = cm.getCache("c2");
assertTrue(cache2 instanceof ConcurrentMapCache);
Cache cache2again = cm.getCache("c2");
assertSame(cache2again, cache2);
Cache cache3 = cm.getCache("c3");
assertTrue(cache3 instanceof ConcurrentMapCache);
Cache cache3again = cm.getCache("c3");
assertSame(cache3again, cache3);
}
@Test
public void testStaticMode() {
ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
Cache cache1 = cm.getCache("c1");
assertTrue(cache1 instanceof ConcurrentMapCache);
Cache cache1again = cm.getCache("c1");
assertSame(cache1again, cache1);
Cache cache2 = cm.getCache("c2");
assertTrue(cache2 instanceof ConcurrentMapCache);
Cache cache2again = cm.getCache("c2");
assertSame(cache2again, cache2);
Cache cache3 = cm.getCache("c3");
assertNull(cache3);
}
}

View File

@@ -31,7 +31,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*
* @author Costin Leau
*/
public abstract class AbstractAnnotationTest {
public abstract class AbstractAnnotationTests {
protected ApplicationContext ctx;

View File

@@ -20,7 +20,7 @@ package org.springframework.cache.config;
/**
* @author Costin Leau
*/
public class AnnotationNamespaceDrivenTest extends AbstractAnnotationTest {
public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
@Override
protected String getConfig() {

View File

@@ -20,7 +20,7 @@ package org.springframework.cache.config;
/**
* @author Costin Leau
*/
public class AnnotationTest extends AbstractAnnotationTest {
public class AnnotationTests extends AbstractAnnotationTests {
@Override
protected String getConfig() {

View File

@@ -22,14 +22,14 @@ import net.sf.ehcache.Element;
import org.junit.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.vendor.AbstractNativeCacheTest;
import org.springframework.cache.vendor.AbstractNativeCacheTests;
/**
* Integration test for EhCache cache.
*
* @author Costin Leau
*/
public class EhCacheCacheTest extends AbstractNativeCacheTest<Ehcache> {
public class EhCacheCacheTests extends AbstractNativeCacheTests<Ehcache> {
@Override
protected Ehcache createNativeCache() throws Exception {

View File

@@ -27,7 +27,7 @@ import org.springframework.cache.Cache;
*
* @author Costin Leau
*/
public abstract class AbstractNativeCacheTest<T> {
public abstract class AbstractNativeCacheTests<T> {
protected T nativeCache;
protected Cache cache;