[jboss-user] [JBoss Cache: Core Edition] - Re: ExpirationPolicy & ClusteredCacheLoader

lovelyliatroim do-not-reply at jboss.com
Fri Mar 6 09:44:10 EST 2009


Sorry for the delay only getting back to this now.

Here is the a test case that i wrote


  | 	@Test public void testFileLoader() throws InterruptedException{
  | 		String persistentCache = CMDSJUnitUtil.getPersistentCache();
  | 		CacheFactory factory = new DefaultCacheFactory();
  | 		Cache cache = factory.createCache(persistentCache);
  | 		cache.create();
  | 		cache.start();
  | 		
  | 		Map<String, String> testData = new HashMap<String,String>();
  | 		testData.put("FirstName", "James");
  | 		testData.put("Surname", "Bond");
  | 		long expirationTime = 15000;
  | 		Fqn path = Fqn.fromString("/testData/bond/james");
  | 		cache.put(path, testData);
  | 		long future = System.currentTimeMillis() + expirationTime;
  | 		cache.put(path,ExpirationConfiguration.EXPIRATION_KEY, future);
  | 
  | 		Thread.sleep(expirationTime + 5000);
  | 		Map data = cache.getData(path);
  | 		assertNull("Node should have been evicted "+data,data);
  | 		
  | 		//Re-add the node to test for restart case
  | 		cache.put(path, testData);
  | 		future = System.currentTimeMillis() + expirationTime;
  | 		cache.put(path,ExpirationConfiguration.EXPIRATION_KEY, future);
  | 
  | 		
  | 		System.out.println("About to stop cache");
  | 		cache.stop();
  | 		cache.destroy();
  | 		
  | 		System.out.println("About to start cache");
  | 		cache.create();
  | 		cache.start();
  | 		
  | 		data = cache.getData(path);
  | 		System.out.println("Data = "+data);
  | 		
  | 		Thread.sleep(expirationTime + 5000);
  | 		
  | 		data = cache.getData(path);
  | 		assertNull("Node should have been evicted",data);
  | 	}
  | 
  | 

This interesting enough actually fails at the very first assert. The cache is configured to use the berkeley DB cache loader. Config is like so


  | <server>
  | 	
  | 		<!-- ==================================================================== -->
  |    <!-- PERSISTENT CACHE CONFIG                                      -->
  |    <!-- ==================================================================== -->
  | 
  |    <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
  |           name="jboss.cache:service=CMDSPersistentCache">
  | 
  |       <depends>jboss:service=Naming</depends>
  |       <depends>jboss:service=TransactionManager</depends>
  | 
  |       <!--
  |           Configure the TransactionManager
  |       
  |       <attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup
  |       </attribute>
  | -->
  | 
  | 	  
  | 	   
  |  <!--
  |           Node locking level : SERIALIZABLE
  |                                REPEATABLE_READ (default)
  |                                READ_COMMITTED
  |                                READ_UNCOMMITTED
  |                                NONE
  |       -->     
  |       <attribute name="IsolationLevel">NONE</attribute>
  | 
  |      <!--
  |            Valid modes are LOCAL
  |                            REPL_ASYNC
  |                            REPL_SYNC
  |                            INVALIDATION_ASYNC
  |                            INVALIDATION_SYNC
  |       -->
  | 	  <attribute name="CacheMode">LOCAL</attribute>
  | 
  |       <!-- Name of cluster. Needs to be the same for all clusters, in order
  |            to find each other
  |       -->
  |       <attribute name="ClusterName">Cluster</attribute>
  | 
  |       <!-- JGroups protocol stack properties NOT NEEDED since CacheMode is LOCAL -->
  | 
  |       <!--
  |           The max amount of time (in milliseconds) we wait until the
  |           state (ie. the contents of the cache) are retrieved from
  |           existing members in a clustered environment
  |       -->
  |       <attribute name="StateRetrievalTimeout">20000</attribute>
  | 
  |       <!--
  |           Number of milliseconds to wait until all responses for a
  |           synchronous call have been received.
  |       -->
  |       <attribute name="SyncReplTimeout">20000</attribute>
  | 
  |       <attribute name="FetchInMemoryState">false</attribute>
  | 
  | 	    
  | 	   
  |       <!-- Max number of milliseconds to wait for a lock acquisition -->
  |       <attribute name="LockAcquisitionTimeout">15000</attribute>
  | 
  | 	   <!-- Specific eviction policy configurations.  -->
  | 	   <attribute name="EvictionPolicyConfig">
  |          <config>
  |             <attribute name="wakeUpIntervalSeconds">2</attribute>
  |             <attribute name="eventQueueSize">200000</attribute>
  |             <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
  |             <region name="/_default_">
  |                <attribute name="maxNodes">100</attribute>
  |                <attribute name="maxAgeSeconds">1</attribute>
  |                <attribute name="timeToLiveSeconds">1</attribute>
  | 			</region>
  | 			 
  | 			 <region name="/testData" policyClass="org.jboss.cache.eviction.ExpirationPolicy" >
  | 				<attribute name="maxNodes">10</attribute>
  |             </region>
  | 			 
  | 		  </config>
  |       </attribute>	   
  | 	   
  | 	  
  | 	   <attribute name="CacheLoaderConfig" replace="false">
  |          <config>
  | 			 <shared>false</shared>
  | 			 <async>true</async>
  | 			 
  | 			<cacheloader>
  |                <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>
  |                <properties>
  |                   location=C:/flatfileDB/node8080
  |                </properties>
  |             </cacheloader>
  | 			 
  |          </config>
  | 	</attribute>
  | 
  |    </mbean>
  | </server>
  | 
  | 

Remove the cacheloader config from the cache configuration and everything runs as you would expect. Using the 2.2.x version of JBC.

Cheers,
LL



View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215730#4215730

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4215730



More information about the jboss-user mailing list