[jbosscache-commits] JBoss Cache SVN: r5733 - in core/trunk/src/test/java/org/jboss/cache: statetransfer and 1 other directory.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Mon Apr 28 12:56:40 EDT 2008
Author: mircea.markus
Date: 2008-04-28 12:56:40 -0400 (Mon, 28 Apr 2008)
New Revision: 5733
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
Log:
JBCACHE-1222 - fixed state transfer test
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-04-28 16:20:15 UTC (rev 5732)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-04-28 16:56:40 UTC (rev 5733)
@@ -1,9 +1,7 @@
package org.jboss.cache.eviction;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
+import org.jboss.cache.*;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
@@ -328,4 +326,21 @@
val = (String) cache.get(rootStr + "3", rootStr + "3");
assertNull("Node should be empty ", val);
}
+
+ public void testOvereviction() throws Exception
+ {
+ Configuration c = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+ Cache<Object, Object> cache1 = new DefaultCacheFactory().createCache(c, true);
+ cache1.put(Fqn.fromString("/base/" + 0), "key", "base" + 0);
+ Node node = cache1.getRoot().getChild(Fqn.fromString("/base/"));
+ node.setResident(true);
+
+ for (int i = 1; i < 5100; i++)
+ {
+ cache1.put(Fqn.fromString("/base/" + i), "key", "base" + i);
+ }
+ Thread.sleep(5000);
+ assertEquals(5000, cache1.getRoot().getChild(Fqn.fromString("/base")).getChildren().size());
+
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2008-04-28 16:20:15 UTC (rev 5732)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2008-04-28 16:56:40 UTC (rev 5733)
@@ -14,7 +14,9 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.Region;
+import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.marshall.InactiveRegionException;
@@ -503,22 +505,35 @@
for (int i = 0; i < 25000; i++)
{
- cache1.put(Fqn.fromString("/base/" + i), "key", "base" + i);
+ cache1.put(Fqn.fromString("/org/jboss/data/" + i), "key", "base" + i);
if (i < 5)
{
cache1.put(Fqn.fromString("/org/jboss/test/data/" + i), "key", "data" + i);
+ if (i == 0)
+ {
+ cache1.getRoot().getChild(Fqn.fromString("/org/jboss/data")).setResident(true); //so that it won't be counted for eviction
+ }
}
}
+ Thread.sleep(5000);
+ assert cache1.getRoot().getChild(Fqn.fromString("/org/jboss/data")).getChildren().size() == 5000;
+
c = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC, true);
final Cache<Object, Object> cache2 = new DefaultCacheFactory().createCache(c, false);
+ log.info("***** before starting the second cache");
cache2.start();
+ log.info("***** after starting the second cache");
caches.put("evict2", cache2);
Node<Object, Object> parent = cache2.getRoot().getChild(Fqn.fromString("/org/jboss/test/data"));
- parent = cache2.getRoot().getChild(Fqn.fromString("/base"));
+ parent = cache2.getRoot().getChild(Fqn.fromString("/org/jboss/data"));
Set children = parent.getChildren();
- assertTrue("Minimum number of base children transferred", children.size() >= 5000);
+ System.out.println("children.size() = " + children.size());
+ System.out.println("cache1.children size = " + cache1.getRoot().getChild(Fqn.fromString("/org/jboss/data")).getChildren().size());
+ log.info("***** cache1.children size = " + cache1.getRoot().getChild(Fqn.fromString("/org/jboss/data")).getChildren().size());
+ log.info("***** children.size() = " + children.size());
+ assertTrue("Minimum number of base children transferred", children.size() >= 4999); //4999 because the root of the region will also be counted, as it is not resident
// Sleep 2.5 secs so the nodes we are about to create in data won't
// exceed the 4 sec TTL when eviction thread runs
@@ -537,7 +552,7 @@
{
try
{
- cache.put(Fqn.fromString("/base/" + i), "key", "base" + i);
+ cache.put(Fqn.fromString("/org/jboss/data/" + i), "key", "base" + i);
cache.put(Fqn.fromString("/org/jboss/test/data/" + i), "key", "data" + i);
i++;
}
@@ -574,14 +589,13 @@
{
System.out.println("data " + dataCount + " < " + maxCountData + " elapsed = " + (System.currentTimeMillis() - start));
sawDataDecrease = true;
- }
- else
+ } else
{
maxCountData = dataCount;
}
}
- parent = cache2.getRoot().getChild(Fqn.fromString("/base"));
+ parent = cache2.getRoot().getChild(Fqn.fromString("/org/jboss/data"));
children = parent.getChildren();
if (children != null)
{
@@ -590,8 +604,7 @@
{
System.out.println("base " + baseCount + " < " + maxCountBase + " elapsed = " + (System.currentTimeMillis() - start));
sawBaseDecrease = true;
- }
- else
+ } else
{
maxCountBase = baseCount;
}
@@ -625,7 +638,7 @@
System.out.println(children.size());
assertTrue("Excess children evicted", children.size() <= 5);
}
- parent = cache2.getRoot().getChild(Fqn.fromString("/base"));
+ parent = cache2.getRoot().getChild(Fqn.fromString("/org/jboss/data"));
children = parent.getChildren();
if (children != null)
{
@@ -645,7 +658,51 @@
}
}
+ /**
+ * tests that after the state transfer takes place the correct number of nodes is being evcited.
+ */
+ public void testEvictionAfterStateTransferSimple() throws Exception
+ {
+ Configuration c = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC, true);
+ String baseRegion = "/base";
+ int maxRegionNodeCount = 5;
+// //set max node node to 5 on default
+ ((LRUConfiguration)c.getEvictionConfig().getEvictionRegionConfigs().get(0).getEvictionPolicyConfig()).setMaxNodes(maxRegionNodeCount);
+ EvictionRegionConfig baseRegionConfig = c.getEvictionConfig().getEvictionRegionConfigs().get(1).clone();
+ baseRegionConfig.setRegionFqn(Fqn.fromString(baseRegion));
+ ((LRUConfiguration)baseRegionConfig.getEvictionPolicyConfig()).setMaxAgeSeconds(1000);
+ ((LRUConfiguration)baseRegionConfig.getEvictionPolicyConfig()).setMaxNodes(maxRegionNodeCount);
+ c.getEvictionConfig().getEvictionRegionConfigs().add(baseRegionConfig);
+
+
+ Cache<Object, Object> cache1 = new DefaultCacheFactory().createCache(c, true);
+ caches.put("evict1", cache1);
+ cache1.getRegion(Fqn.fromString(baseRegion), true).activate();
+
+ for (int i = 0; i < maxRegionNodeCount + 5; i++)
+ {
+ cache1.put(Fqn.fromString(baseRegion + "/" + i), "key", "base" + i);
+ if (i == 0)
+ {
+ cache1.getRoot().getChild(Fqn.fromString(baseRegion)).setResident(true); //so that it won't be counted for eviction
+ }
+ }
+ cache1.put(Fqn.fromString("/org/jboss/test/data/" + 0), "key", "data" + 0);
+
+ Thread.sleep(5000);
+ assert cache1.getRoot().getChild(Fqn.fromString(baseRegion)).getChildren().size() == maxRegionNodeCount;
+ System.out.println("cache1.getRoot().getChild(Fqn.fromString(baseRegion)).getChildren().size() = " + cache1.getRoot().getChild(Fqn.fromString(baseRegion)).getChildren());
+
+ final Cache<Object, Object> cache2 = new DefaultCacheFactory().createCache(c.clone(), false);
+ cache2.start();
+ caches.put("evict2", cache2);
+ Thread.sleep(5000);
+
+ Node parent = cache2.getRoot().getChild(Fqn.fromString(baseRegion));
+ Set children = parent.getChildren();
+ }
+
private class CacheActivator extends CacheUser
{
More information about the jbosscache-commits
mailing list