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 15:28:12 UTC
svn commit: r1520764 - in /shindig/branches/2.5.0-updateX: ./
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 13:28:11 2013
New Revision: 1520764
URL: http://svn.apache.org/r1520764
Log:
SHINDIG-1931 | EhCache provider always uses a singleton cache manager, even if it is the wrong one | Backporting from trunk to the 2.5.0-update branch.
Added:
shindig/branches/2.5.0-updateX/java/common/src/test/resources/testEhCacheConfig.xml (with props)
Modified:
shindig/branches/2.5.0-updateX/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
shindig/branches/2.5.0-updateX/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
shindig/branches/2.5.0-updateX/pom.xml
Modified: shindig/branches/2.5.0-updateX/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.5.0-updateX/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java?rev=1520764&r1=1520763&r2=1520764&view=diff
==============================================================================
--- shindig/branches/2.5.0-updateX/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java (original)
+++ shindig/branches/2.5.0-updateX/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java Sat Sep 7 13:28:11 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/branches/2.5.0-updateX/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.5.0-updateX/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java?rev=1520764&r1=1520763&r2=1520764&view=diff
==============================================================================
--- shindig/branches/2.5.0-updateX/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java (original)
+++ shindig/branches/2.5.0-updateX/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java Sat Sep 7 13:28:11 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/branches/2.5.0-updateX/java/common/src/test/resources/testEhCacheConfig.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.5.0-updateX/java/common/src/test/resources/testEhCacheConfig.xml?rev=1520764&view=auto
==============================================================================
--- shindig/branches/2.5.0-updateX/java/common/src/test/resources/testEhCacheConfig.xml (added)
+++ shindig/branches/2.5.0-updateX/java/common/src/test/resources/testEhCacheConfig.xml Sat Sep 7 13:28:11 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/branches/2.5.0-updateX/java/common/src/test/resources/testEhCacheConfig.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: shindig/branches/2.5.0-updateX/pom.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.5.0-updateX/pom.xml?rev=1520764&r1=1520763&r2=1520764&view=diff
==============================================================================
--- shindig/branches/2.5.0-updateX/pom.xml (original)
+++ shindig/branches/2.5.0-updateX/pom.xml Sat Sep 7 13:28:11 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>