[infinispan-commits] Infinispan SVN: r472 - in trunk/core/src: main/java/org/infinispan/interceptors and 5 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Jun 17 05:53:49 EDT 2009
Author: mircea.markus
Date: 2009-06-17 05:53:49 -0400 (Wed, 17 Jun 2009)
New Revision: 472
Added:
trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java
Modified:
trunk/core/src/main/java/org/infinispan/config/Configuration.java
trunk/core/src/main/java/org/infinispan/interceptors/ReplicationInterceptor.java
trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java
trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd
trunk/core/src/main/resources/xslt/ehcache16x2infinispan4x.xslt
trunk/core/src/test/java/org/infinispan/config/parsing/Jbc2InfinispanTransformerTest.java
trunk/core/src/test/resources/configs/ehcache16/ehcache-configuration.xml
Log:
[ISPN-56] - (Create migration script for EHCache) - reviewed, enhanced and added unit test
Modified: trunk/core/src/main/java/org/infinispan/config/Configuration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/Configuration.java 2009-06-17 09:03:54 UTC (rev 471)
+++ trunk/core/src/main/java/org/infinispan/config/Configuration.java 2009-06-17 09:53:49 UTC (rev 472)
@@ -43,6 +43,8 @@
public class Configuration extends AbstractNamedCacheConfigurationBean {
private static final long serialVersionUID = 5553791890144997466L;
+ private boolean useDeadlockDetection = false;
+
// reference to a global configuration
private GlobalConfiguration globalConfiguration;
@@ -85,7 +87,16 @@
public long getRehashRpcTimeout() {
return rehashRpcTimeout;
}
+
+ public boolean isUseDeadlockDetection() {
+ return useDeadlockDetection;
+ }
+ public void setUseDeadlockDetection(boolean useDeadlockDetection) {
+ this.useDeadlockDetection = useDeadlockDetection;
+ }
+
+
/**
* Cache replication mode.
*/
@@ -401,7 +412,7 @@
testImmutability("syncRollbackPhase");
this.syncRollbackPhase = syncRollbackPhase;
}
-
+
public void setUseEagerLocking(boolean useEagerLocking) {
testImmutability("useEagerLocking");
this.useEagerLocking = useEagerLocking;
@@ -543,7 +554,7 @@
public boolean isSyncRollbackPhase() {
return syncRollbackPhase;
}
-
+
public boolean isUseEagerLocking() {
return useEagerLocking;
}
Modified: trunk/core/src/main/java/org/infinispan/interceptors/ReplicationInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/ReplicationInterceptor.java 2009-06-17 09:03:54 UTC (rev 471)
+++ trunk/core/src/main/java/org/infinispan/interceptors/ReplicationInterceptor.java 2009-06-17 09:53:49 UTC (rev 472)
@@ -21,7 +21,6 @@
*/
package org.infinispan.interceptors;
-import org.infinispan.commands.LockControlCommand;
import org.infinispan.commands.tx.CommitCommand;
import org.infinispan.commands.tx.PrepareCommand;
import org.infinispan.commands.tx.RollbackCommand;
@@ -46,6 +45,7 @@
* @since 4.0
*/
public class ReplicationInterceptor extends BaseRpcInterceptor {
+
@Override
public Object visitCommitCommand(TxInvocationContext ctx, CommitCommand command) throws Throwable {
if (!ctx.isInTxScope()) throw new IllegalStateException("This should not be possible!");
@@ -60,6 +60,7 @@
Object retVal = invokeNextInterceptor(ctx, command);
if (ctx.isOriginLocal() && command.hasModifications()) {
boolean async = configuration.getCacheMode() == Configuration.CacheMode.REPL_ASYNC;
+ boolean useDeadlockDetection = configuration.isUseDeadlockDetection();
rpcManager.broadcastRpcCommand(command, !async, false);
}
return retVal;
Modified: trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java 2009-06-17 09:03:54 UTC (rev 471)
+++ trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java 2009-06-17 09:53:49 UTC (rev 472)
@@ -168,9 +168,13 @@
}
} else {
CacheLoaderConfig cfg = clmConfig.getFirstCacheLoaderConfig();
- tmpLoader = createCacheLoader(cfg, cache);
- if (cfg instanceof CacheStoreConfig)
+ if (cfg != null) {
+ tmpLoader = createCacheLoader(cfg, cache);
+ if (cfg instanceof CacheStoreConfig)
assertNotSingletonAndShared(((CacheStoreConfig) cfg));
+ } else {
+ return null;
+ }
}
// Update the config with those actually used by the loaders
Modified: trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd
===================================================================
--- trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd 2009-06-17 09:03:54 UTC (rev 471)
+++ trunk/core/src/main/resources/schema/infinispan-config-4.0.xsd 2009-06-17 09:53:49 UTC (rev 472)
@@ -203,7 +203,7 @@
<xs:complexType name="loadersType">
<xs:sequence>
- <xs:element name="loader" maxOccurs="unbounded">
+ <xs:element name="loader" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="properties" type="tns:propertiesType"/>
Modified: trunk/core/src/main/resources/xslt/ehcache16x2infinispan4x.xslt
===================================================================
--- trunk/core/src/main/resources/xslt/ehcache16x2infinispan4x.xslt 2009-06-17 09:03:54 UTC (rev 471)
+++ trunk/core/src/main/resources/xslt/ehcache16x2infinispan4x.xslt 2009-06-17 09:53:49 UTC (rev 472)
@@ -11,16 +11,15 @@
<xsl:element name="infinispan">
<xsl:element name="global">
- <xsl:element name="asyncListenerExecutor">
- <xsl:attribute name="factory">org.infinispan.executors.DefaultExecutorFactory</xsl:attribute>
+
+ <asyncListenerExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
+ <property name="threadNamePrefix" value="AsyncTransportThread"/>
+ </asyncListenerExecutor>
+
+ <asyncTransportExecutor factory="org.infinispan.executors.DefaultExecutorFactory">
<property name="threadNamePrefix" value="AsyncListenerThread"/>
- </xsl:element>
+ </asyncTransportExecutor>
- <xsl:element name="asyncSerializationExecutor">
- <xsl:attribute name="factory">org.infinispan.executors.DefaultExecutorFactory</xsl:attribute>
- <property name="threadNamePrefix" value="AsyncSerializationThread"/>
- </xsl:element>
-
<evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
<property name="threadNamePrefix" value="EvictionThread"/>
</evictionScheduledExecutor>
@@ -29,117 +28,143 @@
<property name="threadNamePrefix" value="ReplicationQueueThread"/>
</replicationQueueScheduledExecutor>
- <xsl:element name="globalJmxStatistics">
- <xsl:attribute name="jmxDomain">infinispan</xsl:attribute>
- <xsl:attribute name="enabled">
- <xsl:text>true</xsl:text>
- </xsl:attribute>
+ <globalJmxStatistics jmxDomain="infinispan" enabled="true"/>
+
+ <shutdown hookBehavior="DEFAULT"/>
+ </xsl:element>
+
+ <xsl:for-each select="defaultCache">
+ <xsl:element name="default">
+ <xsl:call-template name="generateCache"/>
</xsl:element>
+ </xsl:for-each>
- <xsl:element name="shutdown">
- <xsl:attribute name="hookBehavior">
- <xsl:text>DEFAULT</xsl:text>
+ <xsl:for-each select="cache">
+ <xsl:element name="namedCache">
+ <xsl:attribute name="name">
+ <xsl:value-of select="@name"/>
</xsl:attribute>
+ <xsl:call-template name="generateCache"/>
</xsl:element>
- </xsl:element>
+ </xsl:for-each>
+ </xsl:element>
+ </xsl:template>
- <xsl:element name="default">
- <xsl:if test="defaultCache[@memoryStoreEvictionPolicy]">
- <xsl:if test="contains(defaultCache[@memoryStoreEvictionPolicy], 'LRU')">
- <xsl:element name="eviction">
- <xsl:attribute name="strategy">
- <xsl:value-of select="defaultCache/@memoryStoreEvictionPolicy"/>
- </xsl:attribute>
- </xsl:element>
+ <xsl:template name="generateCache">
+ <xsl:if test="@memoryStoreEvictionPolicy">
+ <xsl:element name="eviction">
+ <xsl:attribute name="strategy">
+ <xsl:if test="contains(@memoryStoreEvictionPolicy, 'LRU') or contains(@memoryStoreEvictionPolicy, 'FIFO')">
+ <xsl:value-of select="@memoryStoreEvictionPolicy"/>
</xsl:if>
- <xsl:if test="contains(defaultCache[@memoryStoreEvictionPolicy], 'FIFO')">
- <xsl:element name="eviction">
- <xsl:attribute name="strategy">
- <xsl:value-of select="defaultCache/@memoryStoreEvictionPolicy"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- <xsl:if test="contains(defaultCache[@memoryStoreEvictionPolicy], 'LFU')">
+
+ <xsl:if test="contains(@memoryStoreEvictionPolicy, 'LFU')">
<xsl:message terminate="no">WARNING!!! Infinispan does not support LFU eviction. Using LRU instead.
</xsl:message>
- <xsl:element name="eviction">
- <xsl:attribute name="strategy">
- <xsl:text>LRU</xsl:text>
- </xsl:attribute>
- </xsl:element>
+ <xsl:text>LRU</xsl:text>
</xsl:if>
+ </xsl:attribute>
+
+ <xsl:attribute name="wakeUpInterval">
+ <xsl:choose>
+ <xsl:when test="@diskExpiryThreadIntervalSeconds">
+ <xsl:value-of select="concat(@diskExpiryThreadIntervalSeconds,'000')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- by default the value is 120 seconds in EHCache-->
+ <xsl:value-of select="120000"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+
+ <xsl:if test="@maxElementsInMemory">
+ <xsl:attribute name="maxEntries">
+ <xsl:value-of select="@maxElementsInMemory"/>
+ </xsl:attribute>
</xsl:if>
+ </xsl:element>
+ </xsl:if>
+ <xsl:if
+ test="(@timeToIdleSeconds or @timeToLiveSeconds) and not(@eternal = 'true')">
+ <xsl:element name="expiration">
+ <xsl:if test="@timeToIdleSeconds">
+ <xsl:attribute name="maxIdle">
+ <xsl:value-of select="@timeToIdleSeconds"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="@timeToLiveSeconds">
+ <xsl:attribute name="lifespan">
+ <xsl:value-of select="@timeToLiveSeconds"/>
+ </xsl:attribute>
+ </xsl:if>
</xsl:element>
- <xsl:for-each select="cache">
- <xsl:element name="namedCache">
- <xsl:attribute name="name">
- <xsl:value-of select="@name"/>
- </xsl:attribute>
- <xsl:element name="eviction">
- <xsl:attribute name="strategy">
- <xsl:choose>
- <xsl:when test="contains(@memoryStoreEvictionPolicy, 'LRU')">
- <xsl:text>LRU</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="contains(@memoryStoreEvictionPolicy, 'FIFO')">
- <xsl:text>FIFO</xsl:text>
- </xsl:when>
- <xsl:otherwise>
+ </xsl:if>
+
+ <xsl:choose>
+ <xsl:when test="@overflowToDisk='true'">
+ <xsl:if test="/ehcache/defaultCache[@overflowToDisk = 'false'] or not(@name)">
+ <xsl:element name="loaders">
+ <xsl:attribute name="passivation">true</xsl:attribute>
+ <xsl:attribute name="preload">
+ <xsl:value-of select="string(@diskPersistent = 'true')"/>
+ </xsl:attribute>
+ <xsl:element name="loader">
+ <xsl:attribute name="class">org.infinispan.loaders.file.FileCacheStore</xsl:attribute>
+ <xsl:attribute name="purgeOnStartup">
+ <xsl:value-of select="string(@diskPersistent = 'true')"/>
+ </xsl:attribute>
+ <xsl:if test="/ehcache/diskStore[@path]">
+ <properties>
+ <xsl:element name="property">
+ <xsl:attribute name="name">location</xsl:attribute>
+ <xsl:attribute name="value">
<xsl:choose>
- <xsl:when test="contains(@memoryStoreEvictionPolicy, 'LFU')">
- <xsl:text>LRU</xsl:text>
+ <xsl:when
+ test="/ehcache/diskStore[@path='user.home' or @path='user.dir' or @path='java.io.tmpdir']">
+ <xsl:value-of select="concat('${',/ehcache/diskStore/@path,'}')"/>
</xsl:when>
<xsl:otherwise>
- <xsl:text>NONE</xsl:text>
+ <xsl:value-of select="/ehcache/diskStore/@path"/>
</xsl:otherwise>
</xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- </xsl:element>
- <!-- <expiration lifespan="60000" maxIdle="1000" /> -->
- <xsl:element name="expiration">
-
- </xsl:element>
-
- <xsl:if test="cacheEventListenerFactory">
- <xsl:element name="clustering">
- <xsl:if test="cacheEventListenerFactory/@properties">
- <xsl:attribute name="mode">
- <!-- Replication, Invalidation, Distribution-->
- <xsl:text>distribution</xsl:text>
- </xsl:attribute>
- <!-- TODO remove spaces -->
- <xsl:choose>
- <xsl:when test="contains(cacheEventListenerFactory/@properties, 'replicateAsynchronously=false')">
- <xsl:element name="sync">
- <!-- replQueueInterval="100" replQueueMaxElements="200" ?? -->
- <xsl:attribute name="useReplQueue">
- <xsl:text>true</xsl:text>
- </xsl:attribute>
- </xsl:element>
- </xsl:when>
- <xsl:otherwise>
- <xsl:element name="async">
- <!-- replQueueInterval="100" replQueueMaxElements="200" ?? -->
- <xsl:attribute name="useReplQueue">
- <xsl:text>true</xsl:text>
- </xsl:attribute>
- </xsl:element>
- </xsl:otherwise>
- </xsl:choose>
+ </xsl:attribute>
+ </xsl:element>
+ </properties>
</xsl:if>
</xsl:element>
- </xsl:if>
- </xsl:element>
- </xsl:for-each>
- </xsl:element>
-
-
+ </xsl:element>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="/ehcache/defaultCache[@overflowToDisk = 'true']">
+ <!-- if this cache does not overflow to disk then override the possible cache loader definition from 'defaultCache' -->
+ <loaders/>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:if test="cacheEventListenerFactory">
+ <xsl:element name="clustering">
+ <xsl:attribute name="mode">
+ <xsl:choose>
+ <xsl:when test="contains(cacheEventListenerFactory/@properties, 'replicatePutsViaCopy=false')">
+ <xsl:text>invalidation</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>distribution</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+ <xsl:choose>
+ <xsl:when
+ test="contains(cacheEventListenerFactory/@properties, 'replicateAsynchronously=false')">
+ <sync/>
+ </xsl:when>
+ <xsl:otherwise>
+ <async/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:element>
+ </xsl:if>
</xsl:template>
</xsl:stylesheet>
Added: trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java 2009-06-17 09:53:49 UTC (rev 472)
@@ -0,0 +1,88 @@
+package org.infinispan.config.parsing;
+
+import org.infinispan.Cache;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.config.CacheLoaderManagerConfig;
+import org.infinispan.config.Configuration;
+import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.loaders.CacheLoaderConfig;
+import org.infinispan.manager.DefaultCacheManager;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+/**
+ * @author Mircea.Markus at jboss.com
+ */
+ at Test(groups = "functional", testName = "config.parsing.EHCache2InfinispanTransformerTest")
+public class EHCache2InfinispanTransformerTest {
+
+ public static final String XSLT_FILE = "xslt/ehcache16x2infinispan4x.xslt";
+ private static final String BASE_DIR = "configs/ehcache16";
+ ConfigFilesConvertor convertor = new ConfigFilesConvertor();
+
+
+ /**
+ * Transforms and tests the transformation of a complex file.
+ */
+ public void testAllFile() throws Exception {
+ ClassLoader existingCl = Thread.currentThread().getContextClassLoader();
+ DefaultCacheManager dcm = null;
+ Cache<Object, Object> sampleDistributedCache2 = null;
+ try {
+ ClassLoader delegatingCl = new Jbc2InfinispanTransformerTest.TestClassLoader(existingCl);
+ Thread.currentThread().setContextClassLoader(delegatingCl);
+ String fileName = getFileName("/ehcache-configuration.xml");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ convertor.parse(fileName, baos, XSLT_FILE);
+
+
+// File out = new File("zzzz.xml");
+// if (out.exists()) out.delete();
+// out.createNewFile();
+// FileOutputStream fos = new FileOutputStream(out);
+// fos.write(baos.toByteArray());
+// baos.close();
+// fos.close();
+
+ dcm = new DefaultCacheManager(new ByteArrayInputStream(baos.toByteArray()));
+ Cache<Object,Object> defaultCache = dcm.getCache();
+ defaultCache.put("key", "value");
+ Configuration configuration = defaultCache.getConfiguration();
+ assertEquals(configuration.getEvictionMaxEntries(),10000);
+ assertEquals(configuration.getExpirationMaxIdle(), 121);
+ assertEquals(configuration.getExpirationLifespan(), 122);
+ CacheLoaderManagerConfig clmConfig = configuration.getCacheLoaderManagerConfig();
+ assert clmConfig != null;
+ CacheLoaderConfig loaderConfig = clmConfig.getCacheLoaderConfigs().get(0);
+ assert loaderConfig.getCacheLoaderClassName().equals("org.infinispan.loaders.file.FileCacheStore");
+ assertEquals(configuration.getEvictionWakeUpInterval(), 119000);
+ assertEquals(configuration.getEvictionStrategy(), EvictionStrategy.LRU);
+
+ assert dcm.getDefinedCacheNames().indexOf("sampleCache1") > 0;
+ assert dcm.getDefinedCacheNames().indexOf("sampleCache2") > 0;
+ assert dcm.getDefinedCacheNames().indexOf("sampleCache3") > 0;
+ assert dcm.getDefinedCacheNames().indexOf("sampleDistributedCache1") > 0;
+ assert dcm.getDefinedCacheNames().indexOf("sampleDistributedCache2") > 0;
+ assert dcm.getDefinedCacheNames().indexOf("sampleDistributedCache3") > 0;
+
+ sampleDistributedCache2 = dcm.getCache("sampleDistributedCache2");
+ assert sampleDistributedCache2.getConfiguration().getCacheLoaderManagerConfig().getCacheLoaderConfigs().size() == 0;
+ assert sampleDistributedCache2.getConfiguration().getExpirationLifespan() == 101;
+ assert sampleDistributedCache2.getConfiguration().getExpirationMaxIdle() == 102;
+ assertEquals(sampleDistributedCache2.getConfiguration().getCacheMode(), Configuration.CacheMode.INVALIDATION_SYNC);
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(existingCl);
+ TestingUtil.killCaches(sampleDistributedCache2);
+ TestingUtil.killCacheManagers(dcm);
+ }
+ }
+
+ private String getFileName(String s) {
+ return BASE_DIR + File.separator + s;
+ }
+}
Property changes on: trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/core/src/test/java/org/infinispan/config/parsing/Jbc2InfinispanTransformerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/parsing/Jbc2InfinispanTransformerTest.java 2009-06-17 09:03:54 UTC (rev 471)
+++ trunk/core/src/test/java/org/infinispan/config/parsing/Jbc2InfinispanTransformerTest.java 2009-06-17 09:53:49 UTC (rev 472)
@@ -127,7 +127,7 @@
return BASE_DIR + File.separator + s;
}
- static class TestClassLoader extends ClassLoader {
+ public static class TestClassLoader extends ClassLoader {
private ClassLoader existing;
TestClassLoader(ClassLoader existing) {
Modified: trunk/core/src/test/resources/configs/ehcache16/ehcache-configuration.xml
===================================================================
--- trunk/core/src/test/resources/configs/ehcache16/ehcache-configuration.xml 2009-06-17 09:03:54 UTC (rev 471)
+++ trunk/core/src/test/resources/configs/ehcache16/ehcache-configuration.xml 2009-06-17 09:53:49 UTC (rev 472)
@@ -460,13 +460,13 @@
<defaultCache
maxElementsInMemory="10000"
eternal="false"
- timeToIdleSeconds="120"
- timeToLiveSeconds="120"
+ timeToIdleSeconds="121"
+ timeToLiveSeconds="122"
overflowToDisk="true"
diskSpoolBufferSizeMB="30"
maxElementsOnDisk="10000000"
diskPersistent="false"
- diskExpiryThreadIntervalSeconds="120"
+ diskExpiryThreadIntervalSeconds="119"
memoryStoreEvictionPolicy="LRU"
/>
@@ -555,8 +555,8 @@
<cache name="sampleDistributedCache2"
maxElementsInMemory="10"
eternal="false"
- timeToIdleSeconds="100"
- timeToLiveSeconds="100"
+ timeToIdleSeconds="102"
+ timeToLiveSeconds="101"
overflowToDisk="false">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
More information about the infinispan-commits
mailing list