[hibernate-commits] Hibernate SVN: r17244 - in core/branches/INFINISPAN/cache-infinispan: src/main/java/org/hibernate/cache/infinispan and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Aug 6 10:36:33 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-08-06 10:36:33 -0400 (Thu, 06 Aug 2009)
New Revision: 17244

Added:
   core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java
   core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml
   core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
Removed:
   core/branches/INFINISPAN/cache-infinispan/.settings/
   core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/ispn4-configs.xml
Modified:
   core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
   core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java
Log:
[ISPN-6] Defined data type and individual entity/collection configuration properties and added UT for them.

Added: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java	                        (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/DataTypeConfig.java	2009-08-06 14:36:33 UTC (rev 17244)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.hibernate.cache.infinispan;
+
+import java.util.Locale;
+
+import org.infinispan.eviction.EvictionStrategy;
+
+/**
+ * This class represents parameters that can be configured for general 
+ * entity/collection/query/timestamp data type caches and overrides for 
+ * individual entity or collection caches. 
+ * 
+ * @author Galder Zamarreño
+ */
+public class DataTypeConfig {
+   
+   private String cache;
+   
+   private EvictionStrategy strategy;
+   
+   private long wakeUpInterval;
+   
+   private int maxEntries;
+   
+   private long lifespan;
+   
+   private long maxIdle;
+
+   public String getCache() {
+      return cache;
+   }
+
+   public void setCache(String cache) {
+      this.cache = cache;
+   }
+
+   public EvictionStrategy getStrategy() {
+      return strategy;
+   }
+
+   public void setStrategy(String strategy) {
+      this.strategy = EvictionStrategy.valueOf(uc(strategy));
+   }
+
+   public long getWakeUpInterval() {
+      return wakeUpInterval;
+   }
+
+   public void setWakeUpInterval(long wakeUpInterval) {
+      this.wakeUpInterval = wakeUpInterval;
+   }
+
+   public int getMaxEntries() {
+      return maxEntries;
+   }
+
+   public void setMaxEntries(int maxEntries) {
+      this.maxEntries = maxEntries;
+   }
+
+   public long getLifespan() {
+      return lifespan;
+   }
+
+   public void setLifespan(long lifespan) {
+      this.lifespan = lifespan;
+   }
+
+   public long getMaxIdle() {
+      return maxIdle;
+   }
+
+   public void setMaxIdle(long maxIdle) {
+      this.maxIdle = maxIdle;
+   }
+   
+   @Override
+   public String toString() {
+      return new StringBuilder().append(getClass().getSimpleName()).append('{')
+         .append("cache=").append(cache)
+         .append(", strategy=").append(strategy)
+         .append(", wakeUpInterval=").append(wakeUpInterval)
+         .append(", maxEntries=").append(maxEntries)
+         .append(", lifespan=").append(lifespan)
+         .append(", maxIdle=").append(maxIdle)
+         .append('}').toString();
+   }
+
+   private String uc(String s) {
+      return s == null ? null : s.toUpperCase(Locale.ENGLISH);
+   }
+}

Modified: core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java	2009-08-06 14:18:54 UTC (rev 17243)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java	2009-08-06 14:36:33 UTC (rev 17244)
@@ -1,5 +1,9 @@
 package org.hibernate.cache.infinispan;
 
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 
 import org.hibernate.cache.CacheDataDescription;
@@ -25,16 +29,95 @@
  * regions.
  * 
  * @author Chris Bredesen
+ * @author Galder Zamarreño
  */
 public class InfinispanRegionFactory implements RegionFactory {
    
    private static final Logger log = LoggerFactory.getLogger(InfinispanRegionFactory.class);
    
+   private static final String PREFIX = "hibernate.cache.infinispan.";
+   
+   private static final String CONFIG_SUFFIX = ".cfg";
+   
+   private static final String STRATEGY_SUFFIX = ".eviction.strategy";
+
+   private static final String WAKE_UP_INTERVAL_SUFFIX = ".eviction.wake_up_interval";
+   
+   private static final String MAX_ENTRIES_SUFFIX = ".eviction.max_entries";
+   
+   private static final String LIFESPAN_SUFFIX = ".eviction.lifespan";
+   
+   private static final String MAX_IDLE_SUFFIX = ".eviction.max_idle";
+   
+   /** 
+    * Classpath or filesystem resource containing Infinispan configurations the factory should use.
+    * 
+    * @see #DEF_INFINISPAN_CONFIG_RESOURCE
+    */
    public static final String INFINISPAN_CONFIG_RESOURCE_PROP = "hibernate.cache.infinispan.cfg";
+
+   private static final String ENTITY_KEY = "entity";
    
-   public static final String DEF_INFINISPAN_CONFIG_RESOURCE = "org/hibernate/cache/infinispan/builder/ispn4-configs.xml";
+   /**
+    * Name of the configuration that should be used for entity caches.
+    * 
+    * @see #DEF_ENTITY_RESOURCE
+    */
+   public static final String ENTITY_CACHE_RESOURCE_PROP = PREFIX + ENTITY_KEY + CONFIG_SUFFIX;
    
+   private static final String COLLECTION_KEY = "collection";
+   
+   /**
+    * Name of the configuration that should be used for collection caches.
+    * No default value, as by default we try to use the same Infinispan cache
+    * instance we use for entity caching.
+    * 
+    * @see #ENTITY_CACHE_RESOURCE_PROP
+    * @see #DEF_ENTITY_RESOURCE
+    */
+   public static final String COLLECTION_CACHE_RESOURCE_PROP = PREFIX + COLLECTION_KEY + CONFIG_SUFFIX;
+
+   private static final String TIMESTAMP_KEY = "timestamp";
+
+   /**
+    * Name of the configuration that should be used for timestamp caches.
+    * 
+    * @see #DEF_TS_RESOURCE
+    */
+   public static final String TIMESTAMP_CACHE_RESOURCE_PROP = PREFIX + TIMESTAMP_KEY + CONFIG_SUFFIX;
+
+   private static final String QUERY_KEY = "query";
+
+   /**
+    * Name of the configuration that should be used for query caches.
+    * 
+    * @see #DEF_QUERY_RESOURCE
+    */
+   public static final String QUERY_CACHE_RESOURCE_PROP = PREFIX + QUERY_KEY + CONFIG_SUFFIX;
+   
+   /**
+    * Default value for {@link #INFINISPAN_RESOURCE_PROP}. Specifies the "infinispan-configs.xml" file in this package.
+    */
+   public static final String DEF_INFINISPAN_CONFIG_RESOURCE = "org/hibernate/cache/infinispan/builder/infinispan-configs.xml";
+   
+   /**
+    * Default value for {@link #ENTITY_CACHE_RESOURCE_PROP}.
+    */
+   public static final String DEF_ENTITY_RESOURCE = "entity";
+   
+   /**
+    * Default value for {@link #TIMESTAMP_CACHE_RESOURCE_PROP}.
+    */
+   public static final String DEF_TIMESTAMP_RESOURCE = "timestamp";
+   
+   /**
+    * Default value for {@link #QUERY_CACHE_RESOURCE_PROP}.
+    */
+   public static final String DEF_QUERY_RESOURCE = "local-query";
+   
    private CacheManager manager;
+   
+   private final Map<String, DataTypeConfig> configs = new HashMap<String, DataTypeConfig>(); 
 
    /**
     * Create a new instance using the default configuration.
@@ -57,7 +140,6 @@
    public CollectionRegion buildCollectionRegion(String regionName, Properties properties,
             CacheDataDescription metadata) throws CacheException {
       log.debug("Building collection cache region [" + regionName + "]");
-      // TODO: Clarify whether for collections, we should just pick the entity name without the collection name from the CacheManager
       return new InfinispanCollectionRegion(manager.getCache(regionName), regionName, metadata);
    }
 
@@ -67,6 +149,7 @@
    public EntityRegion buildEntityRegion(String regionName, Properties properties,
             CacheDataDescription metadata) throws CacheException {
       log.debug("Building entity cache region [" + regionName + "]");
+      // TODO: check the configs map for this region and do the corresponding work
       return new InfinispanEntityRegion(manager.getCache(regionName), regionName, metadata);
    }
 
@@ -118,6 +201,56 @@
       try {
          String configLoc = PropertiesHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);
          manager = new DefaultCacheManager(configLoc);
+         initDefaultCacheNames();
+         
+         Enumeration keys = properties.propertyNames();
+         while (keys.hasMoreElements()) {
+            String key = (String) keys.nextElement();
+            int prefixLoc = -1;
+            if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
+               DataTypeConfig cfgOverride = null;
+               int suffixLoc = -1;
+               if ((suffixLoc = key.indexOf(CONFIG_SUFFIX)) != -1) {
+                  cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+                  cfgOverride.setCache(PropertiesHelper.extractPropertyValue(key, properties));
+//                  String name = key.substring(prefixLoc + PREFIX.length(), suffixLoc);
+//                  cfgOverride = configs.get(name);
+//                  if (cfgOverride == null) {
+//                     cfgOverride = new DataTypeConfig();
+//                     configs.put(name, cfgOverride);
+//                  }
+//                  String cache = null;
+//                  if (name.equals(ENTITY_CACHE_RESOURCE_PROP)) {
+//                     cache = PropertiesHelper.getString(ENTITY_CACHE_RESOURCE_PROP, properties, DEF_ENTITY_RESOURCE);
+//                  } else if (name.equals(COLLECTION_CACHE_RESOURCE_PROP)) {
+//                     cache = PropertiesHelper.getString(COLLECTION_CACHE_RESOURCE_PROP, properties, DEF_ENTITY_RESOURCE);
+//                  } else if (name.equals(TIMESTAMP_CACHE_RESOURCE_PROP)) {
+//                     cache = PropertiesHelper.getString(TIMESTAMP_CACHE_RESOURCE_PROP, properties, DEF_TIMESTAMP_RESOURCE);
+//                  } else if (name.equals(QUERY_CACHE_RESOURCE_PROP)) {
+//                     cache = PropertiesHelper.getString(QUERY_CACHE_RESOURCE_PROP, properties, DEF_QUERY_RESOURCE);
+//                  } else {
+//                     cache = PropertiesHelper.extractPropertyValue(key, properties);                     
+//                  }
+//                  cfgOverride.setCache(cache);
+               } else if ((suffixLoc = key.indexOf(STRATEGY_SUFFIX)) != -1) {
+                  cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+                  cfgOverride.setStrategy(PropertiesHelper.extractPropertyValue(key, properties));
+               } else if ((suffixLoc = key.indexOf(WAKE_UP_INTERVAL_SUFFIX)) != -1) {
+                  cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+                  cfgOverride.setWakeUpInterval(Long.parseLong(PropertiesHelper.extractPropertyValue(key, properties)));                  
+               } else if ((suffixLoc = key.indexOf(MAX_ENTRIES_SUFFIX)) != -1) {
+                  cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+                  cfgOverride.setMaxEntries(PropertiesHelper.getInt(key, properties, -1));
+               } else if ((suffixLoc = key.indexOf(LIFESPAN_SUFFIX)) != -1) {
+                  cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+                  cfgOverride.setLifespan(Long.parseLong(PropertiesHelper.extractPropertyValue(key, properties)));
+               } else if ((suffixLoc = key.indexOf(MAX_IDLE_SUFFIX)) != -1) {
+                  cfgOverride = getOrCreateConfig(key, prefixLoc, suffixLoc);
+                  cfgOverride.setMaxIdle(Long.parseLong(PropertiesHelper.extractPropertyValue(key, properties)));
+               }  
+            }
+            
+         }
       } catch (CacheException ce) {
          throw ce;
       } catch (Throwable t) {
@@ -132,5 +265,42 @@
       log.debug("Stopping Infinispan CacheManager");
       manager.stop();
    }
+   
+   /**
+    * Returns an unmodifiable map containing configured entity/collection type configuration overrides.
+    * This method should be used primarily for testing/checking purpouses.
+    * 
+    * @return an unmodifiable map.
+    */
+   public Map<String, DataTypeConfig> getConfigs() {
+      return Collections.unmodifiableMap(configs);
+   }
+   
+   private void initDefaultCacheNames() {
+      DataTypeConfig entity = new DataTypeConfig();
+      entity.setCache(DEF_ENTITY_RESOURCE);
+      configs.put(ENTITY_KEY, entity);
 
+      DataTypeConfig collection = new DataTypeConfig();
+      collection.setCache(DEF_ENTITY_RESOURCE);
+      configs.put(COLLECTION_KEY, collection);         
+
+      DataTypeConfig timestamp = new DataTypeConfig();
+      timestamp.setCache(DEF_TIMESTAMP_RESOURCE);
+      configs.put(TIMESTAMP_KEY, timestamp);         
+
+      DataTypeConfig query = new DataTypeConfig();
+      query.setCache(DEF_QUERY_RESOURCE);
+      configs.put(QUERY_KEY, query);      
+   }
+
+   private DataTypeConfig getOrCreateConfig(String key, int prefixLoc, int suffixLoc) {
+      String name = key.substring(prefixLoc + PREFIX.length(), suffixLoc);
+      DataTypeConfig cfgOverride = configs.get(name);
+      if (cfgOverride == null) {
+         cfgOverride = new DataTypeConfig();
+         configs.put(name, cfgOverride);
+      }
+      return cfgOverride;
+   }
 }
\ No newline at end of file

Copied: core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml (from rev 17234, core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/ispn4-configs.xml)
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml	                        (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml	2009-08-06 14:36:33 UTC (rev 17244)
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">
+   <global>
+      <transport transportClass = "org.infinispan.remoting.transport.jgroups.JGroupsTransport" 
+            clusterName="infinispan-hibernate-cluster" distributedSyncTimeout="50000">
+         <!-- Note that the JGroups transport uses sensible defaults if no configuration property is defined. -->
+         <!-- TODO: Change to udp.xml once streaming transfer requirement has been removed.  -->
+         <property name="configurationFile" value="flush-udp.xml"/>
+         <!-- See the JGroupsTransport javadocs for more flags -->
+      </transport>
+      <serialization marshallerClass="org.infinispan.marshall.VersionAwareMarshaller" version="4.0"/>
+   </global>
+
+   <default>
+      <!-- Used to register JMX statistics in any available MBean server -->
+      <jmxStatistics enabled="false"/>   
+   </default>
+
+   <!-- Default configuration is appropriate for entity/collection caching. -->
+   <namedCache name="entity">
+      <clustering mode="invalidation">
+         <stateRetrieval fetchInMemoryState="false" timeout="20000"/>
+         <sync replTimeout="20000"/>
+      </clustering>
+      <!-- Note: REPEATABLE_READ is only useful if the application evicts/clears entities 
+        from the Hibernate Session and then expects to repeatably re-read them in 
+        the same transaction. Otherwise, the Session's internal cache provides a 
+        repeatable-read semantic. Before choosing this config, carefully read the docs
+        and make sure you really need REPEATABLE_READ.
+       -->
+      <locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>      
+      <!--
+         Eviction configuration.  WakeupInterval defines how often the eviction thread runs, in milliseconds.  0 means
+         the eviction thread will never run.  A separate executor is used for eviction in each cache.
+      -->
+      <eviction wakeUpInterval="5000" maxEntries="10000" strategy="FIFO"/>
+      <expiration maxIdle="100000"/>
+      <lazyDeserialization enabled="true"/>      
+   </namedCache>
+
+   <!-- A config appropriate for query caching. Does not replicate
+        queries. DO NOT STORE TIMESTAMPS IN THIS CACHE.
+   -->
+   <namedCache name="local-query">
+      <locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>      
+      <!--
+         Eviction configuration.  WakeupInterval defines how often the eviction thread runs, in milliseconds.  0 means
+         the eviction thread will never run.  A separate executor is used for eviction in each cache.
+      -->
+      <eviction wakeUpInterval="5000" maxEntries="10000" strategy="FIFO"/>
+      <expiration maxIdle="100000"/>
+   </namedCache>
+
+   <!-- Optimized for timestamp caching. A clustered timestamp cache
+        is required if query caching is used, even if the query cache
+        itself is configured with CacheMode=LOCAL.
+   -->
+   <namedCache name="timestamp">
+      <clustering mode="REPL">
+         <stateRetrieval fetchInMemoryState="true" timeout="20000"/>
+         <async/>
+      </clustering>
+      <locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>      
+      <lazyDeserialization enabled="true"/>
+      <!--  Don't ever evict modification timestamps -->
+      <eviction strategy="NONE"/>
+   </namedCache>
+
+</infinispan>
\ No newline at end of file

Deleted: core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/ispn4-configs.xml
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/ispn4-configs.xml	2009-08-06 14:18:54 UTC (rev 17243)
+++ core/branches/INFINISPAN/cache-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/ispn4-configs.xml	2009-08-06 14:36:33 UTC (rev 17244)
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">
-   <global>
-      <transport transportClass = "org.infinispan.remoting.transport.jgroups.JGroupsTransport" 
-            clusterName="infinispan-hibernate-cluster" distributedSyncTimeout="50000">
-         <!-- Note that the JGroups transport uses sensible defaults if no configuration property is defined. -->
-         <!-- TODO: Change to udp.xml once streaming transfer requirement has been removed.  -->
-         <property name="configurationFile" value="flush-udp.xml"/>
-         <!-- See the JGroupsTransport javadocs for more flags -->
-      </transport>
-      <serialization marshallerClass="org.infinispan.marshall.VersionAwareMarshaller" version="4.0"/>
-   </global>
-
-   <!-- Default configuration is appropriate for entity/collection caching. -->
-   <default>
-      <clustering mode="invalidation">
-         <stateRetrieval fetchInMemoryState="false" timeout="20000"/>
-         <sync replTimeout="20000"/>
-      </clustering>
-      <!-- Note: REPEATABLE_READ is only useful if the application evicts/clears entities 
-        from the Hibernate Session and then expects to repeatably re-read them in 
-        the same transaction. Otherwise, the Session's internal cache provides a 
-        repeatable-read semantic. Before choosing this config, carefully read the docs
-        and make sure you really need REPEATABLE_READ.
-       -->
-      <locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>      
-      <!--
-         Eviction configuration.  WakeupInterval defines how often the eviction thread runs, in milliseconds.  0 means
-         the eviction thread will never run.  A separate executor is used for eviction in each cache.
-      -->
-      <eviction wakeUpInterval="5000" maxEntries="10000" strategy="FIFO"/>
-      <expiration maxIdle="100000"/>
-      <lazyDeserialization enabled="true"/>      
-   </default>
-
-   <!-- A config appropriate for query caching. Does not replicate
-        queries. DO NOT STORE TIMESTAMPS IN THIS CACHE.
-   -->
-   <namedCache name="org.hibernate.cache.StandardQueryCache">
-      <locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>      
-      <!--
-         Eviction configuration.  WakeupInterval defines how often the eviction thread runs, in milliseconds.  0 means
-         the eviction thread will never run.  A separate executor is used for eviction in each cache.
-      -->
-      <eviction wakeUpInterval="5000" maxEntries="10000" strategy="FIFO"/>
-      <expiration maxIdle="100000"/>
-   </namedCache>
-
-   <!-- Optimized for timestamp caching. A clustered timestamp cache
-        is required if query caching is used, even if the query cache
-        itself is configured with CacheMode=LOCAL.
-   -->
-   <namedCache name="org.hibernate.cache.UpdateTimestampsCache">
-      <clustering mode="REPL">
-         <stateRetrieval fetchInMemoryState="true" timeout="20000"/>
-         <async/>
-      </clustering>
-      <locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000" lockAcquisitionTimeout="15000"/>      
-      <!--  Don't ever evict modification timestamps -->
-      <lazyDeserialization enabled="true"/>
-   </namedCache>
-
-</infinispan>
\ No newline at end of file

Added: core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java	                        (rev 0)
+++ core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java	2009-08-06 14:36:33 UTC (rev 17244)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.hibernate.test.cache.infinispan;
+
+import java.util.Properties;
+
+import org.hibernate.cache.infinispan.InfinispanRegionFactory;
+import org.infinispan.eviction.EvictionStrategy;
+
+import junit.framework.TestCase;
+
+/**
+ * InfinispanRegionFactoryTestCase.
+ * 
+ * @author Galder Zamarreño
+ */
+public class InfinispanRegionFactoryTestCase extends TestCase {
+
+   public void testConfigurationProcessing() {
+      final String person = "com.acme.Person";
+      final String addresses = "com.acme.Person.addresses";
+      Properties p = new Properties();
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.cfg", "person-cache");
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy", "LRU");
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.wake_up_interval", "2000");
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.max_entries", "5000 ");
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.lifespan", "60000");
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.max_idle", "30000");
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.cfg", "person-addresses-cache");
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.lifespan", "120000");      
+      p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.max_idle", "60000");
+      p.setProperty("hibernate.cache.infinispan.query.cfg", "my-query-cache");
+      p.setProperty("hibernate.cache.infinispan.query.eviction.strategy", "FIFO");
+      p.setProperty("hibernate.cache.infinispan.query.eviction.wake_up_interval", "3000");
+      p.setProperty("hibernate.cache.infinispan.query.eviction.max_entries", "10000");
+      
+      InfinispanRegionFactory factory = new InfinispanRegionFactory();
+      factory.start(null, p);
+
+      assertEquals("entity", factory.getConfigs().get("entity").getCache());
+      assertEquals("entity", factory.getConfigs().get("collection").getCache());
+      assertEquals("timestamp", factory.getConfigs().get("timestamp").getCache());
+      
+      assertEquals("person-cache", factory.getConfigs().get(person).getCache());
+      assertEquals(EvictionStrategy.LRU, factory.getConfigs().get(person).getStrategy());
+      assertEquals(2000, factory.getConfigs().get(person).getWakeUpInterval());
+      assertEquals(5000, factory.getConfigs().get(person).getMaxEntries());
+      assertEquals(60000, factory.getConfigs().get(person).getLifespan());
+      assertEquals(30000, factory.getConfigs().get(person).getMaxIdle());
+
+      assertEquals("person-addresses-cache", factory.getConfigs().get(addresses).getCache());
+      assertEquals(120000, factory.getConfigs().get(addresses).getLifespan());
+      assertEquals(60000, factory.getConfigs().get(addresses).getMaxIdle());
+      
+      assertEquals("my-query-cache", factory.getConfigs().get("query").getCache());
+      assertEquals(EvictionStrategy.FIFO, factory.getConfigs().get("query").getStrategy());
+      assertEquals(3000, factory.getConfigs().get("query").getWakeUpInterval());
+      assertEquals(10000, factory.getConfigs().get("query").getMaxEntries());
+   }
+   
+   public void testTimestampNoEvictionValidation() {
+      // Timestamp cache cannot have evictions configured, so add corresponding test.
+   }
+}

Modified: core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java	2009-08-06 14:18:54 UTC (rev 17243)
+++ core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanTest.java	2009-08-06 14:36:33 UTC (rev 17244)
@@ -3,6 +3,9 @@
 import org.hibernate.cache.infinispan.InfinispanRegionFactory;
 import org.hibernate.test.cache.BaseRegionFactoryTestCase;
 
+/**
+ * TODO: what is this exactly testing???
+ */
 public class InfinispanTest extends BaseRegionFactoryTestCase {
 
 	public InfinispanTest( String x ) {



More information about the hibernate-commits mailing list