You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ss...@apache.org on 2013/09/07 14:53:04 UTC

svn commit: r1520761 - in /shindig/trunk: ./ java/common/src/main/java/org/apache/shindig/common/cache/ehcache/ java/common/src/test/java/org/apache/shindig/common/cache/ehcache/ java/common/src/test/resources/

Author: ssievers
Date: Sat Sep  7 12:53:03 2013
New Revision: 1520761

URL: http://svn.apache.org/r1520761
Log:
SHINDIG-1931 | EhCache provider always uses a singleton cache manager, even if it is the wrong one

Added:
    shindig/trunk/java/common/src/test/resources/testEhCacheConfig.xml   (with props)
Modified:
    shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
    shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
    shindig/trunk/pom.xml

Modified: shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java?rev=1520761&r1=1520760&r2=1520761&view=diff
==============================================================================
--- shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java (original)
+++ shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java Sat Sep  7 12:53:03 2013
@@ -90,7 +90,7 @@ public class EhCacheCacheProvider implem
       System.setProperty("ehcache.disk.store.dir", System.getProperty("java.io.tmpdir"));
     }
 
-    cacheManager = CacheManager.create(getConfiguration(configPath));
+    cacheManager = CacheManager.newInstance(getConfiguration(configPath));
     create(jmxEnabled, withCacheStats);
     cleanupHandler.register(this);
   }

Modified: shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java?rev=1520761&r1=1520760&r2=1520761&view=diff
==============================================================================
--- shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java (original)
+++ shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java Sat Sep  7 12:53:03 2013
@@ -18,13 +18,15 @@
  */
 package org.apache.shindig.common.cache.ehcache;
 
+import net.sf.ehcache.CacheManager;
+
 import org.apache.shindig.common.cache.Cache;
 import org.apache.shindig.common.cache.CacheProvider;
-
 import org.apache.shindig.common.servlet.GuiceServletContextListener;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.powermock.reflect.Whitebox;
 
 /**
  *
@@ -56,4 +58,27 @@ public class EhCacheCacheProviderTest {
     Assert.assertEquals(cache.getCapacity(), cache2.getCapacity());
     Assert.assertEquals(cache.getSize(), cache2.getSize());
   }
+
+  @Test
+  public void testCacheManagerDuplication() throws Exception {
+    EhCacheCacheProvider duplicateDefaultProvider = new EhCacheCacheProvider(
+            "res://org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml",
+            "org/apache/shindig/common/cache/ehcache/SizeOfFilter.txt",
+            false,
+            true,
+            new GuiceServletContextListener.CleanupHandler());
+    Assert.assertSame("Cache managers are the same",
+                         Whitebox.getInternalState(defaultProvider, "cacheManager"),
+                         Whitebox.getInternalState(duplicateDefaultProvider, "cacheManager"));
+
+    EhCacheCacheProvider differentProvider = new EhCacheCacheProvider(
+            "res://testEhCacheConfig.xml",
+            "org/apache/shindig/common/cache/ehcache/SizeOfFilter.txt",
+            false,
+            true,
+            new GuiceServletContextListener.CleanupHandler());
+    Assert.assertNotSame("Cache managers are different",
+            Whitebox.getInternalState(defaultProvider, "cacheManager"),
+            Whitebox.getInternalState(differentProvider, "cacheManager"));
+  }
 }

Added: shindig/trunk/java/common/src/test/resources/testEhCacheConfig.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/resources/testEhCacheConfig.xml?rev=1520761&view=auto
==============================================================================
--- shindig/trunk/java/common/src/test/resources/testEhCacheConfig.xml (added)
+++ shindig/trunk/java/common/src/test/resources/testEhCacheConfig.xml Sat Sep  7 12:53:03 2013
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<!--
+  The one and only cache manager for Shindig.
+
+  Allot a modest amount of heap to be shared by all caches.
+
+  By default only the CompiledJs caches will overflow to disk.  No caches will persist
+  to disk by default as a development aid.  It is recommended that deployments tune
+  caches to their needs.
+
+  Statistics are turned on for every cache by default.  This affects cache performance.
+  To turn stats off you can use shindig.cache.ehcache.jmx.stats in shindig.properties.
+
+  See http://ehcache.org/ehcache.xsd for more information on valid configuration.
+-->
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:noNamespaceSchemaLocation="ehcache.xsd"
+  updateCheck="false"
+  maxBytesLocalHeap="50m"
+  name="ShindigTestCM">
+
+  <!--
+    The directory where any caches configured as diskPersistent or overflowToDisk
+    will end up.
+  -->
+  <diskStore path="ehcache.disk.store.dir"/>
+
+  <!-- Default sizeOfPolicy for computing the size of cache elements in memory -->
+  <sizeOfPolicy maxDepth="1000" maxDepthExceededBehavior="abort"/>
+
+
+  <!--
+    Mandatory Default Cache configuration. These settings will be applied to caches
+    created programmatically using CacheManager.add(String cacheName).
+
+    The defaultCache has an implicit name "default" which is a reserved cache name.
+  -->
+  <defaultCache
+    statistics="true"
+    eternal="false"
+    timeToIdleSeconds="300"
+    timeToLiveSeconds="600"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!--
+    Compiled feature code, 10Mb disk overflow
+  -->
+  <cache name="CompiledJs"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="true"
+    diskPersistent="false"
+    maxBytesLocalDisk="10m"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!--
+    gadget specs and message bundles have additional caching policies that
+    allow us to cache the objects indefinitely when using an LFU or LRU cache.
+  -->
+  <cache name="gadgetSpecs"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <cache name="messageBundles"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!-- Used to cache parsed HTML DOMs based on their content -->
+  <cache name="parsedDocuments"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!-- Used to cache parsed CSS DOMs based on their content -->
+  <cache name="parsedCss"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!--
+    This configuration is only suitable for a modest sized HTTP cache.
+    You should configure a shared cache for production use.
+    Give this cache 30% of the local heap by default.
+  -->
+  <cache name="httpResponses"
+    maxBytesLocalHeap="30%"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!-- Used to cache parsed expressions based on their content -->
+  <cache name="expressions"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!-- Used to cache cajoled modules based on their content -->
+  <cache name="cajoledModules"
+    statistics="true"
+    eternal="false"
+    timeToIdleSeconds="300"
+    timeToLiveSeconds="600"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU"/>
+
+  <!-- Used to cache Gadget Feature JS -->
+  <cache name="FeatureJsCache"
+    statistics="true"
+    eternal="true"
+    overflowToDisk="false"
+    diskPersistent="false"
+    memoryStoreEvictionPolicy="LFU">
+    <!--
+      The elements stored in this cache are complex and the default sizeOfPolicy
+      is insufficient
+    -->
+    <sizeOfPolicy maxDepth="5000" maxDepthExceededBehavior="abort"/>
+  </cache>
+</ehcache>

Propchange: shindig/trunk/java/common/src/test/resources/testEhCacheConfig.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: shindig/trunk/pom.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/pom.xml?rev=1520761&r1=1520760&r2=1520761&view=diff
==============================================================================
--- shindig/trunk/pom.xml (original)
+++ shindig/trunk/pom.xml Sat Sep  7 12:53:03 2013
@@ -1488,6 +1488,12 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-api-easymock</artifactId>
+      <version>1.5.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>xmlunit</groupId>
       <artifactId>xmlunit</artifactId>
       <version>1.3</version>