[jbosscache-commits] JBoss Cache SVN: r4528 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Oct 2 13:29:42 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-10-02 13:29:42 -0400 (Tue, 02 Oct 2007)
New Revision: 4528

Modified:
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
Log:
[JBCACHE-1192] Add test of gravitating nodes only found in cache loader.

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java	2007-10-02 16:38:00 UTC (rev 4527)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java	2007-10-02 17:29:42 UTC (rev 4528)
@@ -9,13 +9,21 @@
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertTrue;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.jboss.cache.Cache;
 import org.jboss.cache.CacheImpl;
+import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.LRUConfiguration;
 import org.jboss.cache.loader.CacheLoader;
 import org.jboss.cache.misc.TestingUtil;
+import org.testng.annotations.Test;
 
 /**
  * Tests use of the data gravitator alongside other cache loaders as well as data gravitator options such as removeOnFind.
@@ -134,12 +142,25 @@
       assertTrue("should not exist in loaders2", !loaders[2].exists(b2));
    }
 
-   public void testWithDataGravitationEviction() throws Exception
+   /**
+    * Tests data gravitation when "removeOnFind=false"; i.e. nodes
+    * from which data is gravitated evict it instead of removing it.
+    * 
+    * @throws Exception
+    */
+   public void testWithDataGravitationEvictOnFind() throws Exception
    {
       dataGravitationEvictionTest(true);
    }
 
-   public void testWithDataGravitationEvictionNoAuto() throws Exception
+   /**
+    * Tests data gravitation when auto-gravitation is disabled and 
+    * "removeOnFind=false"; i.e. nodes from which data is gravitated 
+    * evict it instead of removing it.
+    * 
+    * @throws Exception
+    */
+   public void testWithDataGravitationEvictOnFindNoAuto() throws Exception
    {
       dataGravitationEvictionTest(false);
    }
@@ -206,5 +227,57 @@
       assertTrue("should not exist in loaders2", !loaders[2].exists(b1));
       assertTrue("should not exist in loaders2", !loaders[2].exists(b2));
    }
+   
+   /**
+    * Tests whether nodes that have been evicted can successfully be
+    * gravitated.
+    * 
+    * @throws Exception
+    */
+   public void testGravitationOfEvictedNodes() throws Exception
+   {
+      CacheImpl<Object,Object> cache0 = createCacheWithCacheLoader(true, true, passivation, true, false);
+      Configuration cfg0 = cache0.getConfiguration();
+      configureEviction(cfg0);
+      Configuration cfg1 = cfg0.clone();
+      CacheImpl<Object,Object> cache1 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg1, false);
+      
+      // Store them for the teardown method
+      if (caches == null)
+         caches = new ArrayList<CacheImpl<Object,Object>>();
+      caches.add(cache0);
+      caches.add(cache1);
+      
+      cache0.start();
+      cache1.start();
+      
+      TestingUtil.blockUntilViewsReceived((Cache[]) caches.toArray(new Cache[2]), VIEW_BLOCK_TIMEOUT);
+      TestingUtil.sleepThread(getSleepTimeout());
+      
+      Fqn foo = Fqn.fromString("/foo");
+      cache0.put(foo, "key", "value");
 
+      // Sleep long enough for eviction to run twice plus a bit
+      TestingUtil.sleepThread(2050);
+      
+      assertEquals("Passivated value available from buddy", "value", cache1.get(foo, "key"));
+   }
+
+   private void configureEviction(Configuration cfg)
+   {
+      EvictionConfig ec = new EvictionConfig();
+      ec.setWakeupIntervalSeconds(1);
+      EvictionRegionConfig erc = new EvictionRegionConfig();
+      erc.setRegionName("/_default_");
+      LRUConfiguration epc = new LRUConfiguration();
+      epc.setMaxAgeSeconds(2);
+      epc.setTimeToLiveSeconds(1);
+      epc.setMaxNodes(1);
+      erc.setEvictionPolicyConfig(epc);
+      List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>();
+      ercs.add(erc);
+      ec.setEvictionRegionConfigs(ercs);
+      cfg.setEvictionConfig(ec);
+   }
+
 }




More information about the jbosscache-commits mailing list