cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1486003 - in /cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/cache/ test/java/org/apache/cayenne/cache/ test/resources/org/apache/cayenne/cache/
Date Fri, 24 May 2013 10:52:46 GMT
Author: aadamchik
Date: Fri May 24 10:52:46 2013
New Revision: 1486003

URL: http://svn.apache.org/r1486003
Log:
CAY-1827 EhCache region corresponding to a cache group loses it settings after 'removeGroup'

(cherry picked from commit 54214fb732cc8bc284c19654d72bfc71d188900d)

Added:
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
      - copied, changed from r1485943, cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/org/apache/cayenne/cache/
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/org/apache/cayenne/cache/test-ehcache.xml
Modified:
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java?rev=1486003&r1=1486002&r2=1486003&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/EhCacheQueryCache.java
Fri May 24 10:52:46 2013
@@ -20,6 +20,7 @@ package org.apache.cayenne.cache;
 
 import java.util.List;
 
+import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Ehcache;
 import net.sf.ehcache.Element;
@@ -96,7 +97,7 @@ public class EhCacheQueryCache implement
 
         // create empty cache for cache group here, as we have a factory to
         // create an object, and should never ever return null from this
-        // method
+        // method.
         Ehcache cache = cacheManager.addCacheIfAbsent(cacheName);
         Element result = cache.get(key);
 
@@ -170,7 +171,10 @@ public class EhCacheQueryCache implement
     }
 
     public void removeGroup(String groupKey) {
-        cacheManager.removeCache(groupKey);
+        Ehcache cache = cacheManager.getEhcache(groupKey);
+        if(cache != null) {
+            cache.removeAll();
+        }
     }
 
     public void clear() {

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java?rev=1486003&r1=1486002&r2=1486003&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
Fri May 24 10:52:46 2013
@@ -97,4 +97,27 @@ public class EhCacheQueryCacheTest exten
         cache.put(md, results);
         assertSame(results, cache.get(md));
     }
+
+    public void testRemoveGroup_WithFactory_WithCacheGroups() {
+
+        EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
+
+        Object[] lists = new Object[] { new ArrayList<Object>(), new ArrayList<Object>(),
new ArrayList<Object>() };
+        QueryCacheEntryFactory factory = mock(QueryCacheEntryFactory.class);
+        when(factory.createObject()).thenReturn(lists[0], lists[1], lists[2]);
+
+        QueryMetadata md = mock(QueryMetadata.class);
+        when(md.getCacheKey()).thenReturn("k1");
+        when(md.getCacheGroups()).thenReturn(new String[] { "cg1" });
+
+        assertEquals(lists[0], cache.get(md, factory));
+        assertEquals(lists[0], cache.get(md, factory));
+
+        cache.removeGroup("cg0");
+        assertEquals(lists[0], cache.get(md, factory));
+
+        cache.removeGroup("cg1");
+        assertEquals(lists[1], cache.get(md, factory));
+
+    }
 }

Copied: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
(from r1485943, cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java?p2=cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java&p1=cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java&r1=1485943&r2=1486003&rev=1486003&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCacheTest.java
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/cache/EhCacheQueryCache_WithConfigTest.java
Fri May 24 10:52:46 2013
@@ -21,21 +21,24 @@ package org.apache.cayenne.cache;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.net.URL;
 import java.util.ArrayList;
-import java.util.List;
 
 import junit.framework.TestCase;
+import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 
 import org.apache.cayenne.query.QueryMetadata;
 
-public class EhCacheQueryCacheTest extends TestCase {
+public class EhCacheQueryCache_WithConfigTest extends TestCase {
 
-    private CacheManager cacheManager;
+    protected CacheManager cacheManager;
 
     @Override
     protected void setUp() throws Exception {
-        cacheManager = new CacheManager();
+        URL config = getClass().getResource("test-ehcache.xml");
+        assertNotNull(config);
+        cacheManager = new CacheManager(config);
     }
 
     @Override
@@ -43,21 +46,7 @@ public class EhCacheQueryCacheTest exten
         cacheManager.shutdown();
     }
 
-    public void testGet() {
-
-        EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
-
-        QueryMetadata md = mock(QueryMetadata.class);
-        when(md.getCacheKey()).thenReturn("k1");
-
-        assertNull(cache.get(md));
-
-        List<?> results = new ArrayList<Object>();
-        cache.put(md, results);
-        assertSame(results, cache.get(md));
-    }
-
-    public void testGet_WithFactory() {
+    public void testRemoveGroup_WithFactory_WithCacheGroups() {
 
         EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
 
@@ -67,34 +56,29 @@ public class EhCacheQueryCacheTest exten
 
         QueryMetadata md = mock(QueryMetadata.class);
         when(md.getCacheKey()).thenReturn("k1");
+        when(md.getCacheGroups()).thenReturn(new String[] { "cg1" });
 
         assertEquals(lists[0], cache.get(md, factory));
         assertEquals(lists[0], cache.get(md, factory));
-        assertEquals(lists[0], cache.get(md, factory));
-
-        List<?> results = new ArrayList<Object>();
-        cache.put(md, results);
-        assertSame(results, cache.get(md));
-    }
 
-    public void testGet_WithFactory_WithCacheGroups() {
+        Cache c1 = cache.cacheManager.getCache("cg1");
+        assertEquals(201, c1.getCacheConfiguration().getTimeToLiveSeconds());
 
-        EhCacheQueryCache cache = new EhCacheQueryCache(cacheManager);
-
-        Object[] lists = new Object[] { new ArrayList<Object>(), new ArrayList<Object>(),
new ArrayList<Object>() };
-        QueryCacheEntryFactory factory = mock(QueryCacheEntryFactory.class);
-        when(factory.createObject()).thenReturn(lists[0], lists[1], lists[2]);
+        // remove non-existing
+        cache.removeGroup("cg0");
+        assertEquals(lists[0], cache.get(md, factory));
 
-        QueryMetadata md = mock(QueryMetadata.class);
-        when(md.getCacheKey()).thenReturn("k1");
-        when(md.getCacheGroups()).thenReturn(new String[] { "cg1" });
+        Cache c2 = cache.cacheManager.getCache("cg1");
+        assertSame(c1, c2);
+        assertEquals(201, c2.getCacheConfiguration().getTimeToLiveSeconds());
 
-        assertEquals(lists[0], cache.get(md, factory));
-        assertEquals(lists[0], cache.get(md, factory));
-        assertEquals(lists[0], cache.get(md, factory));
+        cache.removeGroup("cg1");
+        assertEquals(lists[1], cache.get(md, factory));
 
-        List<?> results = new ArrayList<Object>();
-        cache.put(md, results);
-        assertSame(results, cache.get(md));
+        // make sure the cache still has all the configured settings after
+        // 'removeGroup'
+        Cache c3 = cache.cacheManager.getCache("cg1");
+        assertSame(c1, c3);
+        assertEquals(201, c3.getCacheConfiguration().getTimeToLiveSeconds());
     }
 }

Added: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/org/apache/cayenne/cache/test-ehcache.xml
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/org/apache/cayenne/cache/test-ehcache.xml?rev=1486003&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/org/apache/cayenne/cache/test-ehcache.xml
(added)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/resources/org/apache/cayenne/cache/test-ehcache.xml
Fri May 24 10:52:46 2013
@@ -0,0 +1,10 @@
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
+	monitoring="off" dynamicConfig="false">
+
+	<defaultCache eternal="false" overflowToDisk="false" timeToIdleSeconds="453" timeToLiveSeconds="453"
/>
+
+	<cache name="cg1" timeToLiveSeconds="201" />
+	<cache name="cg2" timeToLiveSeconds="319" />
+
+</ehcache>
\ No newline at end of file



Mime
View raw message