JBoss Cache SVN: r5479 - core/trunk/src/test/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-31 13:53:52 -0400 (Mon, 31 Mar 2008)
New Revision: 5479
Added:
core/trunk/src/test/java/org/jboss/cache/marshall/InvalidRegionForStateTransferTest.java
Log:
JBCACHE-1170 - added test
Added: core/trunk/src/test/java/org/jboss/cache/marshall/InvalidRegionForStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/InvalidRegionForStateTransferTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/InvalidRegionForStateTransferTest.java 2008-03-31 17:53:52 UTC (rev 5479)
@@ -0,0 +1,90 @@
+package org.jboss.cache.marshall;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Region;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * This test ensures the CacheMarshaller doesn't use stale regions when attempting to unmarshall state transfers. Seen intermittently
+ * when async replication is used, since JGroups doesn't attempt to marshall a return value, thereby leaving a stale region in thread local
+ * in the cache marshaller, which then gets reused when the thread is reused to provide state.
+ * <p/>
+ * Need to ensure that the same thread is used to process incoming requests as well as state transfers, hence limiting the JGroups
+ * thread pool size to 1.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Test(groups = "functional")
+public class InvalidRegionForStateTransferTest
+{
+ Cache<Object, Object> c1, c2;
+
+ @BeforeMethod
+ public void setUp() throws CloneNotSupportedException
+ {
+ c1 = new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_ASYNC), false);
+
+ String jgroupsCfg = c1.getConfiguration().getClusterConfig();
+
+ // make sure we use STATE_TRANSFER and not STREAMING_STATE_TRANSFER, so the same thread pool is used for incoming calls and ST
+ jgroupsCfg = jgroupsCfg.replace("STREAMING_STATE_TRANSFER", "STATE_TRANSFER");
+ // also make sure we use a thread pool size of 1
+ jgroupsCfg = jgroupsCfg.replaceFirst("thread_pool.max_threads=[0-9]*;", "thread_pool.max_threads=1;");
+
+ System.out.println(">>>> " + jgroupsCfg);
+ c1.getConfiguration().setClusterConfig(jgroupsCfg);
+
+ c1.getConfiguration().setUseRegionBasedMarshalling(true);
+ c1.start();
+
+ c2 = new DefaultCacheFactory<Object, Object>().createCache(c1.getConfiguration().clone());
+
+ TestingUtil.blockUntilViewsReceived(60000, c1, c2);
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(c1, c2);
+ }
+
+ public void testUseOfInvalidRegion()
+ {
+ Fqn fqn = Fqn.fromString("/a/b/c/d");
+ c1.getRegion(fqn.getParent(), true).registerContextClassLoader(getClass().getClassLoader());
+ c2.getRegion(fqn.getParent(), true).registerContextClassLoader(getClass().getClassLoader());
+
+ // write something; will cause a stale region to be stored in C2's cache marshaller
+ c1.put(fqn, "k", "v");
+ assert c1.get(fqn, "k").equals("v");
+
+ TestingUtil.sleepThread(250); // async repl
+
+ // assert that this made it to c2
+ assert c2.get(fqn, "k").equals("v");
+
+ // c2's cache marshaller's thread local would be polluted now.
+
+ // restart c1 so that it forces a state transfer from c2
+ c1.destroy();
+ c1.create();
+ Region r = c1.getRegion(fqn.getParent(), true);
+ r.registerContextClassLoader(getClass().getClassLoader());
+ r.deactivate();
+ c1.start();
+
+ TestingUtil.blockUntilViewsReceived(60000, c1, c2);
+
+ // assert that the state has been transferred to C1
+ assert c1.get(fqn, "k").equals("v");
+ }
+}
16 years, 9 months
JBoss Cache SVN: r5478 - core/trunk/src/test/java/org/jboss/cache/eviction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-31 11:51:54 -0400 (Mon, 31 Mar 2008)
New Revision: 5478
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
Log:
Allow for no default regions to be set
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-03-31 15:47:52 UTC (rev 5477)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java 2008-03-31 15:51:54 UTC (rev 5478)
@@ -88,15 +88,7 @@
regionManager.getRegion(A_B_C, true).setEvictionPolicy(config);
regionManager.getRegion(A_B, true).setEvictionPolicy(config);
- try
- {
- regionManager.getRegion(Fqn.fromString("/a"), Region.Type.EVICTION, false);
- fail("If we don't setCache the default region, we should throw a RTE!");
- }
- catch (Exception expected)
- {
- // This is ok. Should throw an runtime exception
- }
+ regionManager.getRegion(Fqn.fromString("/a"), Region.Type.EVICTION, false);
}
public void testGetRegion()
16 years, 9 months
JBoss Cache SVN: r5477 - core/trunk/src/test/java/org/jboss/cache/eviction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-31 11:47:52 -0400 (Mon, 31 Mar 2008)
New Revision: 5477
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
Log:
JBCACHE-1315 - Cleaned up unit tests - removed arbitrary sleep times to work around the imprecision described in JBCACHE-1315
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-03-28 17:22:39 UTC (rev 5476)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-03-31 15:47:52 UTC (rev 5477)
@@ -30,6 +30,9 @@
{
CacheSPI<Object, Object> cache;
int wakeupIntervalMillis_ = 0;
+ int dataRegionTTLMillis = 6000;
+ int testRegionTTLMillis = 4000;
+
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
final long DURATION = 10000;
@@ -38,9 +41,19 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- initCaches();
+ Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+ EvictionConfig evConfig = conf.getEvictionConfig();
+ evConfig.setWakeupIntervalSeconds(1);
+ List<EvictionRegionConfig> regionConfigs = new ArrayList<EvictionRegionConfig>();
+ regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/org/jboss/test/data", 5, dataRegionTTLMillis / 1000));
+ regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/test", 10000, testRegionTTLMillis / 1000));
+ evConfig.setEvictionRegionConfigs(regionConfigs);
+ conf.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ conf.setIsolationLevel(IsolationLevel.SERIALIZABLE);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(conf);
+
wakeupIntervalMillis_ = cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
- log("wakeupInterval is " + wakeupIntervalMillis_);
+ System.out.println("-- wakeupInterval is " + wakeupIntervalMillis_);
if (wakeupIntervalMillis_ < 0)
{
fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
@@ -50,21 +63,6 @@
isTrue = true;
}
- public void initCaches() throws Exception
- {
- Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
- EvictionConfig evConfig = conf.getEvictionConfig();
- evConfig.setWakeupIntervalSeconds(5);
- List<EvictionRegionConfig> regionConfigs = new ArrayList<EvictionRegionConfig>();
- regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/org/jboss/test/data", 5, 6));
- regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/test", 10000, 4));
- evConfig.setEvictionRegionConfigs(regionConfigs);
- conf.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- conf.setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(conf);
- }
-
-
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
@@ -75,8 +73,6 @@
{
String rootStr = "/org/jboss/test/data/inuse/";
Fqn fqn;
- // cache_.put("/", "a", "b");
- // TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
for (int i = 0; i < 10; i++)
{
@@ -85,11 +81,9 @@
cache.put(fqn, str, str);
}
- System.out.println("***************************** marking as in-use");
+ System.out.println("-- Marking as in-use");
cache.getRegionManager().getRegion(Fqn.fromString(rootStr + 5), false).markNodeCurrentlyInUse(Fqn.fromString(rootStr + 5), 0);
-// TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
-
for (int i = 10; i < 15; i++)
{
String str = rootStr + i;
@@ -139,16 +133,8 @@
System.out.println(cache.toString());
TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
System.out.println(cache.toString());
- try
- {
- String val = (String) cache.get(rootStr + "3", rootStr + "3");
- assertNull("DataNode should be empty ", val);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail("Failed to get" + e);
- }
+ String val = (String) cache.get(rootStr + "3", rootStr + "3");
+ assertNull("Node should be empty ", val);
}
public void testNodeVisited()
@@ -161,47 +147,32 @@
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
- try
- {
- cache.put(fqn, str, str);
- }
- catch (Exception e)
- {
- fail("Failed to insert data" + e);
- e.printStackTrace();
- }
+ cache.put(fqn, str, str);
}
int period = (wakeupIntervalMillis_ / 2 + 500);
- log("sleeping for " + period + "ms");
- TestingUtil.sleepThread(period);// it really depends the eviction thread time.
+ System.out.println("-- sleeping for " + period + "ms");
+ TestingUtil.sleepThread(period);
String str = rootStr + "7";
Fqn fqn = Fqn.fromString(str);
- try
- {
- cache.get(fqn, str);// just to keep it fresh
- System.out.println("-- sleeping for " + period + "ms");
- TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- cache.get(fqn, str);// just to keep it fresh
- System.out.println("-- sleeping for " + period + "ms");
- TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- String val = (String) cache.get(rootStr + "3", rootStr + "3");
- System.out.println("-- val=" + val);
- assertNull("DataNode should be empty ", val);
- val = (String) cache.get(rootStr + "7", rootStr + "7");
- System.out.println("-- val=" + val);
- assertNotNull("DataNode should not be empty ", val);
- System.out.println("-- sleeping for " + (wakeupIntervalMillis_ + 1000) + "ms");
- TestingUtil.sleepThread(wakeupIntervalMillis_ + 1000);
- val = (String) cache.get(rootStr + "7", rootStr + "7");
- System.out.println("-- val=" + val);
- assertNull("DataNode should be empty ", val);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail("Failed to evict" + e);
- }
+ cache.get(fqn, str);// just to keep it fresh
+ System.out.println("-- sleeping for " + period + "ms");
+ TestingUtil.sleepThread(period);
+ cache.get(fqn, str);// just to keep it fresh
+ System.out.println("-- sleeping for " + period + "ms");
+ TestingUtil.sleepThread(period);
+ String val = (String) cache.get(rootStr + "3", rootStr + "3");
+ System.out.println("-- val=" + val);
+ assertNull("Node should be empty ", val);
+ val = (String) cache.get(rootStr + "7", rootStr + "7");
+ System.out.println("-- val=" + val);
+ assertNotNull("Node should not be empty ", val);
+ period = dataRegionTTLMillis + wakeupIntervalMillis_ + 500; // this is the TTL for nodes + time for the eviction thread to kick in
+ System.out.println("-- sleeping for " + period + "ms");
+ TestingUtil.sleepThread(period);
+ val = (String) cache.get(rootStr + "7", rootStr + "7");
+ System.out.println("-- val=" + val);
+ assertNull("Node should be empty ", val);
}
public void testNodeRemoved()
@@ -211,44 +182,28 @@
{
String str = rootStr + i + "/" + i;
Fqn fqn = Fqn.fromString(str);
- try
- {
- cache.put(fqn, str, str);
- }
- catch (Exception e)
- {
- fail("Failed to insert data" + e);
- e.printStackTrace();
- }
+ cache.put(fqn, str, str);
}
int period = (wakeupIntervalMillis_ / 2 + 500);
- log("period is " + period);
+ System.out.println("-- period is " + period);
// TestingUtil.sleepThread(period); // it really depends the eviction thread time.
String str1 = rootStr + "7";
Fqn fqn1 = Fqn.fromString(str1);
String str2 = rootStr + "7/7";
Fqn fqn2 = Fqn.fromString(str2);
- try
- {
- cache.get(fqn1, str1);// just to keep it fresh
- cache.get(fqn2, str2);// just to keep it fresh
- TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- cache.get(fqn1, str1);// just to keep it fresh
- cache.get(fqn2, str2);// just to keep it fresh
- TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- String val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
- assertNotNull("DataNode should not be empty ", val);
- cache.removeNode(fqn1);
- TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
- val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
- assertNull("DataNode should be empty ", val);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail("Failed to evict" + e);
- }
+ cache.get(fqn1, str1);// just to keep it fresh
+ cache.get(fqn2, str2);// just to keep it fresh
+ TestingUtil.sleepThread(period);
+ cache.get(fqn1, str1);// just to keep it fresh
+ cache.get(fqn2, str2);// just to keep it fresh
+ TestingUtil.sleepThread(period);
+ String val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
+ assertNotNull("Node should not be empty ", val);
+ cache.removeNode(fqn1);
+ TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
+ val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
+ assertNull("Node should be empty ", val);
}
public void testCompleteRemoval() throws Exception
@@ -263,8 +218,10 @@
// Give eviction time to run a few times, then confirm parent
// is completely gone
- TestingUtil.sleepThread((wakeupIntervalMillis_ * 4) + 100);
- assertFalse("Parent completely removed", cache.getRoot().hasChild(parent));
+ int period = (wakeupIntervalMillis_ + testRegionTTLMillis) * 2;
+ System.out.println("-- Sleeping for " + period);
+ TestingUtil.sleepThread(period);
+ assertFalse("Parent not completely removed", cache.getRoot().hasChild(parent));
}
@@ -322,7 +279,7 @@
{
fail("Exception generated in put() " + t1_ex);
}
- log("nodes/locks: " + cache.getNumberOfNodes() + "/" + cache.getNumberOfLocksHeld());
+ System.out.println("-- nodes/locks: " + cache.getNumberOfNodes() + "/" + cache.getNumberOfLocksHeld());
TestingUtil.sleepThread(1000);
if (counter > 10)
{// run for 10 seconds
@@ -334,68 +291,36 @@
public void testForEvictionInternalError()
{
- try
+ String rootStr = "/test/testdata";
+
+ for (int i = 0; i < 10; i++)
{
- // String rootStr = "org/jboss/test/data/";
- String rootStr = "/test/testdata";
+ String str = rootStr + i;
+ Fqn fqn = Fqn.fromString(str);
+ cache.put(fqn, str, str);
+ }
- for (int i = 0; i < 10; i++)
- {
- String str = rootStr + i;
- Fqn fqn = Fqn.fromString(str);
- try
- {
- cache.put(fqn, str, str);
- }
- catch (Exception e)
- {
- fail("Failed to insert data" + e);
- e.printStackTrace();
- }
- }
+ // wait for an eviction
+ TestingUtil.sleepThread(2 * (wakeupIntervalMillis_ + testRegionTTLMillis));
- // wait for an eviction
- TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 2000);
+ String val = (String) cache.get(rootStr + "3", rootStr + "3");
+ assertNull("Node should be empty ", val);
- String val = (String) cache.get(rootStr + "3", rootStr + "3");
- assertNull("DataNode should be empty ", val);
-
- // reinsert the elements
- for (int i = 0; i < 10; i++)
- {
- String str = rootStr + i;
- Fqn fqn = Fqn.fromString(str);
- try
- {
- cache.put(fqn, str, str);
- }
- catch (Exception e)
- {
- fail("Failed to insert data" + e);
- e.printStackTrace();
- }
- }
-
- // clear the root
- cache.removeNode(Fqn.ROOT);
-
- // wait for an eviction
- TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 1000);
-
- val = (String) cache.get(rootStr + "3", rootStr + "3");
- assertNull("DataNode should be empty ", val);
-
- }
- catch (Exception e)
+ // reinsert the elements
+ for (int i = 0; i < 10; i++)
{
- e.printStackTrace();
- fail("Failed to get" + e);
+ String str = rootStr + i;
+ Fqn fqn = Fqn.fromString(str);
+ cache.put(fqn, str, str);
}
- }
- void log(String msg)
- {
- System.out.println("-- " + msg);
- }
+ // clear the root
+ cache.removeNode(Fqn.ROOT);
+ // wait for an eviction
+ TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 1000);
+
+ val = (String) cache.get(rootStr + "3", rootStr + "3");
+ assertNull("Node should be empty ", val);
+ }
}
16 years, 9 months
JBoss Cache SVN: r5476 - core/trunk/src/test/java/org/jboss/cache/eviction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-28 13:22:39 -0400 (Fri, 28 Mar 2008)
New Revision: 5476
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
Log:
JBCACHE-1315 - Cleaned up unit tests - removed arbitrary sleep times to work around the imprecision described in JBCACHE-1315
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-03-28 15:43:37 UTC (rev 5475)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-03-28 17:22:39 UTC (rev 5476)
@@ -1,15 +1,13 @@
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -19,177 +17,129 @@
* @author Ben Wang, Feb 11, 2004
* @author Daniel Huang (dhuang(a)jboss.org)
*/
-@Test(groups = {"functional"})
+@Test(groups = "functional")
public class LRUAlgorithmTest
{
- RegionManager regionManager_;
- LRUAlgorithm algo_;
- LRUConfiguration config_;
+ RegionManager regionManager;
+ LRUAlgorithm algorithm;
+ LRUConfiguration config;
Log log = LogFactory.getLog(LRUAlgorithm.class);
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- algo_ = new LRUAlgorithm();
- config_ = new LRUConfiguration();
- config_.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
+ algorithm = new LRUAlgorithm();
+ config = new LRUConfiguration();
+ config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
// We have to setCache timeToLiveSeconds!!
- config_.setTimeToLiveSeconds(0);
+ config.setTimeToLiveSeconds(0);
- regionManager_ = new RegionManager();
- regionManager_.getRegion("/a/b", true).setEvictionPolicy(config_);
- /*
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- */
+ regionManager = new RegionManager();
+ regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
}
/**
* maxNodes = 1. Eception is evictFromCacheNode. Should be commented for now.
*/
- public void XtestEvictException()
+ public void testEvictException() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(1);
region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+ assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
+
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+
+ assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
* maxNodes = 0 case
*/
- public void testMaxNode1()
+ public void testMaxNode1() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(0);
region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size should be ", 2, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+ assertEquals("Queue size should be ", 2, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
* maxNodes = 1
*/
- public void testMaxNode2()
+ public void testMaxNode2() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(1);
region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+ assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
+
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size should be ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+
+ algorithm.process(region);
+
+ assertEquals("Queue size should be ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
* TimeToIdleSeconds = 0
*/
- public void testIdleTimeSeconds1()
+ public void testIdleTimeSeconds1() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(0);
config.setTimeToLiveSeconds(0);
region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
- TestingUtil.sleepThread(2000);
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size should be ", 2, algo_.getEvictionQueue().getNumberOfNodes());
+ TestingUtil.sleepThread(500);
+
+ algorithm.process(region);
+
+ assertEquals("Queue size should be ", 2, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
* TimeToIdleSeconds = 1
*/
- public void testIdleTimeSeconds2()
+ public void testIdleTimeSeconds2() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(0);
config.setTimeToLiveSeconds(1);
@@ -197,38 +147,25 @@
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(2000);
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #2: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+
+ assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+ TestingUtil.sleepThread(1100);
+
+ algorithm.process(region);
+
+ assertEquals("Queue size #2: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
* TimeToIdleSeconds = 1 with node visited in between.
*/
- public void testIdleTimeSeconds3()
+ public void testIdleTimeSeconds3() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(0);
config.setTimeToLiveSeconds(1);
@@ -236,28 +173,14 @@
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(2000);
+ algorithm.process(region);
+
+ assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+ TestingUtil.sleepThread(1100);
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.VISIT_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #2: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+
+ algorithm.process(region);
+ assertEquals("Queue size #2: ", 1, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
@@ -270,7 +193,7 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(0);
config.setTimeToLiveSeconds(0);
@@ -279,11 +202,11 @@
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- algo_.process(region);
- assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(2000);
- algo_.process(region);
- assertEquals("Queue size #2: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+ assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+ TestingUtil.sleepThread(1100);
+ algorithm.process(region);
+ assertEquals("Queue size #2: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
@@ -291,43 +214,44 @@
*
* @throws Exception
*/
- public void testMaxAgeSeconds2() throws Exception
+ public void testMaxAgeSeconds2() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(0);
config.setTimeToLiveSeconds(0);
- config.setMaxAgeSeconds(2);
+ config.setMaxAgeSeconds(1);
region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- algo_.process(region);
- assertEquals("Queue size #1: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(1000);
- algo_.process(region);
- assertEquals("Queue size #2: ", 3, algo_.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(1500);
- algo_.process(region);
- assertEquals("Queue size #3: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+ assertEquals("Queue size #1: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+ TestingUtil.sleepThread(500);
+ algorithm.process(region);
+ assertEquals("Queue size #2: ", 3, algorithm.getEvictionQueue().getNumberOfNodes());
+ TestingUtil.sleepThread(600);
+ algorithm.process(region);
+ assertEquals("Queue size #3: ", 0, algorithm.getEvictionQueue().getNumberOfNodes());
}
/**
* Generic combo case.
*/
- public void testCombo1()
+ public void testCombo1() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
Fqn fqn4 = Fqn.fromString("/a/b/f");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
+ // Should have a maximum of 2 nodes.
config.setMaxNodes(2);
config.setTimeToLiveSeconds(1);
config.setMaxAgeSeconds(3);
@@ -335,55 +259,42 @@
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn4, NodeEventType.ADD_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #1: ", 2, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+ EvictionQueue eq = algorithm.getEvictionQueue();
+
+ int numNodesInQueue = eq.getNumberOfNodes();
+ assert 2 == numNodesInQueue : "Queue size #1: expected 2 but was " + numNodesInQueue;
+
+ // make sure all nodes now expire
+ TestingUtil.sleepThread(1100);
+
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- TestingUtil.sleepThread(2000);
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #2: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
- TestingUtil.sleepThread(3500);
+ numNodesInQueue = eq.getNumberOfNodes();
+ assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " + numNodesInQueue;
+
+ TestingUtil.sleepThread(3100);
// visit the node now to prevent the idle time from doing the pruning - node still gets pruned but by
// max age.
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxAge: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #3: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+
+ algorithm.process(region);
+
+ numNodesInQueue = eq.getNumberOfNodes();
+ assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " + numNodesInQueue;
}
/**
* Generic combo case with newly added node should be around.
*/
- public void testCombo2()
+ public void testCombo2() throws EvictionException
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxNodes(2);
@@ -392,50 +303,34 @@
region.putNodeEvent(new EvictedEventNode(fqn1, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.ADD_NODE_EVENT));
region.putNodeEvent(new EvictedEventNode(fqn2, NodeEventType.REMOVE_NODE_EVENT));
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #1: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+
+ algorithm.process(region);
+
+ EvictionQueue eq = algorithm.getEvictionQueue();
+ int numNodesInQueue = eq.getNumberOfNodes();
+ assert 1 == numNodesInQueue : "Queue size #1: expected 1 but was " + numNodesInQueue;
+
+ // make sure existing events all time out
+ TestingUtil.sleepThread(1100);
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.ADD_NODE_EVENT));
- TestingUtil.sleepThread(2000);
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testMaxNode: process failed " + e);
- e.printStackTrace();
- }
- assertEquals("Queue size #2: ", 1, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
- TestingUtil.sleepThread(3000);
+ numNodesInQueue = eq.getNumberOfNodes();
+ assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " + numNodesInQueue;
+
+ TestingUtil.sleepThread(3100);
region.putNodeEvent(new EvictedEventNode(fqn3, NodeEventType.VISIT_NODE_EVENT));
- TestingUtil.sleepThread(500);
- try
- {
- algo_.process(region);
- }
- catch (EvictionException e)
- {
- fail("testCombo: process failed " + e);
- e.printStackTrace();
- }
- TestingUtil.sleepThread(1000); // Fairly random ?
- assertEquals("Queue size #3: ", 0, algo_.getEvictionQueue().getNumberOfNodes());
+ algorithm.process(region);
+
+ numNodesInQueue = eq.getNumberOfNodes();
+ assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " + numNodesInQueue;
}
- public void testEvictionSortOrder() throws Exception
+ public void testEvictionSortOrder() throws EvictionException
{
- Region region = regionManager_.getRegion("/a/b", true);
+ Region region = regionManager.getRegion("/a/b", true);
LRUConfiguration config = (LRUConfiguration) region.getEvictionPolicyConfig();
config.setMaxAgeSeconds(1000);
@@ -448,10 +343,8 @@
region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
}
- algo_.process(region);
+ algorithm.process(region);
- TestingUtil.sleepThread(5000);
-
for (int i = 0; i < 100; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
@@ -461,9 +354,9 @@
}
}
- algo_.process(region);
+ algorithm.process(region);
- LRUQueue queue = (LRUQueue) algo_.getEvictionQueue();
+ LRUQueue queue = (LRUQueue) algorithm.getEvictionQueue();
NodeEntry ne;
int count = 0;
@@ -487,7 +380,7 @@
region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT));
}
- algo_.process(region);
+ algorithm.process(region);
long lastCreateTimestamp = 0;
while ((ne = queue.getFirstMaxAgeNodeEntry()) != null)
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-03-28 15:43:37 UTC (rev 5475)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-03-28 17:22:39 UTC (rev 5476)
@@ -15,8 +15,8 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
/**
* Unit tests for LRU Policy.
@@ -25,10 +25,10 @@
* @author Daniel Huang - dhuang(a)jboss.org
* @version $Revision$
*/
-@Test(groups = {"functional"})
+@Test(groups = "functional")
public class LRUPolicyTest
{
- CacheSPI<Object, Object> cache_;
+ CacheSPI<Object, Object> cache;
int wakeupIntervalMillis_ = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
@@ -39,7 +39,7 @@
public void setUp() throws Exception
{
initCaches();
- wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
+ wakeupIntervalMillis_ = cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
log("wakeupInterval is " + wakeupIntervalMillis_);
if (wakeupIntervalMillis_ < 0)
{
@@ -52,37 +52,23 @@
public void initCaches() throws Exception
{
- Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,true);
+ Configuration conf = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
EvictionConfig evConfig = conf.getEvictionConfig();
evConfig.setWakeupIntervalSeconds(5);
List<EvictionRegionConfig> regionConfigs = new ArrayList<EvictionRegionConfig>();
- regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/org/jboss/test/data", 5, 4));
+ regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/org/jboss/test/data", 5, 6));
regionConfigs.add(UnitTestCacheConfigurationFactory.buildLruEvictionRegionConfig("/test", 10000, 4));
evConfig.setEvictionRegionConfigs(regionConfigs);
conf.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
conf.setIsolationLevel(IsolationLevel.SERIALIZABLE);
- cache_ = (CacheSPI) new DefaultCacheFactory().createCache(conf);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(conf);
}
- private EvictionRegionConfig buildEvictionRegionConfig(String regionName, int timeToLive, int maxNodes)
- {
- EvictionRegionConfig erc = new EvictionRegionConfig();
- erc.setRegionName(regionName);
- LRUConfiguration lruConfig = new LRUConfiguration();
- lruConfig.setMaxNodes(5000);
- lruConfig.setTimeToLiveSeconds(1000);
- erc.setEvictionPolicyConfig(lruConfig);
- List<EvictionRegionConfig> erConfigs = new ArrayList<EvictionRegionConfig>();
- erConfigs.add(erc);
- return null;
-
- }
-
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache_.stop();
+ cache.stop();
}
public void testInUseEviction() throws Exception
@@ -96,36 +82,40 @@
{
String str = rootStr + i;
fqn = Fqn.fromString(str);
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
- TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
System.out.println("***************************** marking as in-use");
- cache_.getRegionManager().getRegion(Fqn.fromString(rootStr + 5), false).markNodeCurrentlyInUse(Fqn.fromString(rootStr + 5), 0);
+ cache.getRegionManager().getRegion(Fqn.fromString(rootStr + 5), false).markNodeCurrentlyInUse(Fqn.fromString(rootStr + 5), 0);
+// TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
+
for (int i = 10; i < 15; i++)
{
String str = rootStr + i;
fqn = Fqn.fromString(str);
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
for (int i = 0; i < 5; i++)
{
- assertNull(cache_.getNode(Fqn.fromString(rootStr + i)));
+ Fqn f = Fqn.fromString(rootStr + i);
+ assert null == cache.getNode(f) : f + " should be null";
}
- assertNotNull(cache_.getNode(Fqn.fromString(rootStr + 5)));
+ assertNotNull(cache.getNode(Fqn.fromString(rootStr + 5)));
for (int i = 6; i < 11; i++)
{
- assertNull(cache_.getNode(Fqn.fromString(rootStr + i)));
+ Fqn f = Fqn.fromString(rootStr + i);
+ assert null == cache.getNode(f) : f + " should be null";
}
for (int i = 11; i < 15; i++)
{
- assertNotNull(cache_.getNode(Fqn.fromString(rootStr + i)));
+ Fqn f = Fqn.fromString(rootStr + i);
+ assert null != cache.getNode(f) : f + " should not be null";
}
}
@@ -138,7 +128,7 @@
Fqn fqn = Fqn.fromString(str);
try
{
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
catch (Exception e)
{
@@ -146,12 +136,12 @@
e.printStackTrace();
}
}
- System.out.println(cache_.toString());
+ System.out.println(cache.toString());
TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
- System.out.println(cache_.toString());
+ System.out.println(cache.toString());
try
{
- String val = (String) cache_.get(rootStr + "3", rootStr + "3");
+ String val = (String) cache.get(rootStr + "3", rootStr + "3");
assertNull("DataNode should be empty ", val);
}
catch (Exception e)
@@ -165,7 +155,7 @@
{
String rootStr = "/org/jboss/test/data/";
- System.out.println("REGIONS: " + cache_.getRegionManager().dumpRegions());
+ System.out.println("REGIONS: " + cache.getRegionManager().dumpRegions());
for (int i = 0; i < 10; i++)
{
@@ -173,7 +163,7 @@
Fqn fqn = Fqn.fromString(str);
try
{
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
catch (Exception e)
{
@@ -189,21 +179,21 @@
Fqn fqn = Fqn.fromString(str);
try
{
- cache_.get(fqn, str);// just to keep it fresh
+ cache.get(fqn, str);// just to keep it fresh
System.out.println("-- sleeping for " + period + "ms");
TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- cache_.get(fqn, str);// just to keep it fresh
+ cache.get(fqn, str);// just to keep it fresh
System.out.println("-- sleeping for " + period + "ms");
TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- String val = (String) cache_.get(rootStr + "3", rootStr + "3");
+ String val = (String) cache.get(rootStr + "3", rootStr + "3");
System.out.println("-- val=" + val);
assertNull("DataNode should be empty ", val);
- val = (String) cache_.get(rootStr + "7", rootStr + "7");
+ val = (String) cache.get(rootStr + "7", rootStr + "7");
System.out.println("-- val=" + val);
assertNotNull("DataNode should not be empty ", val);
System.out.println("-- sleeping for " + (wakeupIntervalMillis_ + 1000) + "ms");
TestingUtil.sleepThread(wakeupIntervalMillis_ + 1000);
- val = (String) cache_.get(rootStr + "7", rootStr + "7");
+ val = (String) cache.get(rootStr + "7", rootStr + "7");
System.out.println("-- val=" + val);
assertNull("DataNode should be empty ", val);
}
@@ -223,7 +213,7 @@
Fqn fqn = Fqn.fromString(str);
try
{
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
catch (Exception e)
{
@@ -241,17 +231,17 @@
Fqn fqn2 = Fqn.fromString(str2);
try
{
- cache_.get(fqn1, str1);// just to keep it fresh
- cache_.get(fqn2, str2);// just to keep it fresh
+ cache.get(fqn1, str1);// just to keep it fresh
+ cache.get(fqn2, str2);// just to keep it fresh
TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- cache_.get(fqn1, str1);// just to keep it fresh
- cache_.get(fqn2, str2);// just to keep it fresh
+ cache.get(fqn1, str1);// just to keep it fresh
+ cache.get(fqn2, str2);// just to keep it fresh
TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- String val = (String) cache_.get(rootStr + "7/7", rootStr + "7/7");
+ String val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
assertNotNull("DataNode should not be empty ", val);
- cache_.removeNode(fqn1);
+ cache.removeNode(fqn1);
TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
- val = (String) cache_.get(rootStr + "7/7", rootStr + "7/7");
+ val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
assertNull("DataNode should be empty ", val);
}
catch (Exception e)
@@ -268,13 +258,13 @@
// Add a parent, then a child. LRU will evict the parent,
// then the child, leaving behind an empty parent
Fqn<String> parent = Fqn.fromString(rootStr + "parent");
- cache_.put(parent, "key", "value");
- cache_.put(new Fqn<String>(parent, "child"), "key", "value");
+ cache.put(parent, "key", "value");
+ cache.put(new Fqn<String>(parent, "child"), "key", "value");
// Give eviction time to run a few times, then confirm parent
// is completely gone
TestingUtil.sleepThread((wakeupIntervalMillis_ * 4) + 100);
- assertFalse("Parent completely removed", cache_.getRoot().hasChild(parent));
+ assertFalse("Parent completely removed", cache.getRoot().hasChild(parent));
}
@@ -294,7 +284,7 @@
{
try
{
- cache_.put(myName + i++, "value", i);
+ cache.put(myName + i++, "value", i);
sleep(1);
}
catch (Throwable e)
@@ -312,12 +302,12 @@
public void testConcurrentPutAndEvict() throws Exception
{
- cache_.stop();
- cache_.destroy();
- cache_.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- cache_.create();
- cache_.start();
- cache_.put(ROOT_STR + "/concurrentPutAndEvict", "value", 1);
+ cache.stop();
+ cache.destroy();
+ cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+ cache.create();
+ cache.start();
+ cache.put(ROOT_STR + "/concurrentPutAndEvict", "value", 1);
for (int i = 0; i < 10; i++)
{
@@ -332,7 +322,7 @@
{
fail("Exception generated in put() " + t1_ex);
}
- log("nodes/locks: " + cache_.getNumberOfNodes() + "/" + cache_.getNumberOfLocksHeld());
+ log("nodes/locks: " + cache.getNumberOfNodes() + "/" + cache.getNumberOfLocksHeld());
TestingUtil.sleepThread(1000);
if (counter > 10)
{// run for 10 seconds
@@ -355,7 +345,7 @@
Fqn fqn = Fqn.fromString(str);
try
{
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
catch (Exception e)
{
@@ -367,7 +357,7 @@
// wait for an eviction
TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 2000);
- String val = (String) cache_.get(rootStr + "3", rootStr + "3");
+ String val = (String) cache.get(rootStr + "3", rootStr + "3");
assertNull("DataNode should be empty ", val);
// reinsert the elements
@@ -377,7 +367,7 @@
Fqn fqn = Fqn.fromString(str);
try
{
- cache_.put(fqn, str, str);
+ cache.put(fqn, str, str);
}
catch (Exception e)
{
@@ -387,12 +377,12 @@
}
// clear the root
- cache_.removeNode(Fqn.ROOT);
+ cache.removeNode(Fqn.ROOT);
// wait for an eviction
TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 1000);
- val = (String) cache_.get(rootStr + "3", rootStr + "3");
+ val = (String) cache.get(rootStr + "3", rootStr + "3");
assertNull("DataNode should be empty ", val);
}
16 years, 9 months
JBoss Cache SVN: r5475 - core/trunk/src/main/java/org/jboss/cache/eviction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-28 11:43:37 -0400 (Fri, 28 Mar 2008)
New Revision: 5475
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java
Log:
JBCACHE-1315 - Modification timestamps on eviction events should be captured when the event occurs; not when the eviction thread analyses the events.
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -145,33 +145,31 @@
int count = 0;
while ((node = region.takeLastEventNode()) != null)
{
- Fqn fqn = node.getFqn();
+// Fqn fqn = node.getFqn();
count++;
switch (node.getEventType())
{
case ADD_NODE_EVENT:
- this.processAddedNodes(fqn,
- node.getElementDifference(),
- node.isResetElementCount());
+ this.processAddedNodes(node);
break;
case REMOVE_NODE_EVENT:
- this.processRemovedNodes(fqn);
+ this.processRemovedNodes(node);
break;
case VISIT_NODE_EVENT:
- this.processVisitedNodes(fqn);
+ this.processVisitedNodes(node);
break;
case ADD_ELEMENT_EVENT:
- this.processAddedElement(fqn);
+ this.processAddedElement(node);
break;
case REMOVE_ELEMENT_EVENT:
- this.processRemovedElement(fqn);
+ this.processRemovedElement(node);
break;
case MARK_IN_USE_EVENT:
- this.processMarkInUseNodes(fqn, node.getInUseTimeout());
+ this.processMarkInUseNodes(node.getFqn(), node.getInUseTimeout());
break;
case UNMARK_USE_EVENT:
- this.processUnmarkInUseNodes(fqn);
+ this.processUnmarkInUseNodes(node.getFqn());
break;
default:
throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
@@ -271,8 +269,22 @@
}
}
- protected void processAddedNodes(Fqn fqn, int numAddedElements, boolean resetElementCount) throws EvictionException
+ /**
+ * Convenience method, which calls {@link #processAddedNodes(EvictedEventNode, int, boolean)} using values in the
+ * evictedEventNode for number of added elements and the resetElementCount flag.
+ *
+ * @param evictedEventNode an evictedEventNode to process
+ * @throws EvictionException on problems
+ */
+ protected void processAddedNodes(EvictedEventNode evictedEventNode) throws EvictionException
{
+ processAddedNodes(evictedEventNode, evictedEventNode.getElementDifference(), evictedEventNode.isResetElementCount());
+ }
+
+ protected void processAddedNodes(EvictedEventNode evictedEventNode, int numAddedElements, boolean resetElementCount) throws EvictionException
+ {
+ Fqn fqn = evictedEventNode.getFqn();
+
if (log.isTraceEnabled())
{
log.trace("Adding node " + fqn + " with " + numAddedElements + " elements to eviction queue");
@@ -281,7 +293,7 @@
NodeEntry ne = evictionQueue.getNodeEntry(fqn);
if (ne != null)
{
- ne.setModifiedTimeStamp(System.currentTimeMillis());
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
if (resetElementCount)
{
@@ -295,25 +307,14 @@
{
log.trace("Queue already contains " + ne.getFqn() + " processing it as visited");
}
- this.processVisitedNodes(ne.getFqn());
+ processVisitedNodes(evictedEventNode);
return;
}
- long stamp = System.currentTimeMillis();
ne = new NodeEntry(fqn);
- ne.setModifiedTimeStamp(stamp);
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
ne.setNumberOfNodeVisits(1);
ne.setNumberOfElements(numAddedElements);
- // add it to the node map and eviction queue
-// if (evictionQueue.containsNodeEntry(ne))
-// {
-// if (log.isTraceEnabled())
-// {
-// log.trace("Queue already contains " + ne.getFqn() + " processing it as visited");
-// }
-// this.processVisitedNodes(ne.getFqn());
-// return;
-// }
evictionQueue.addNodeEntry(ne);
@@ -336,11 +337,12 @@
* Because EvictionQueues are collections, when iterating them from an iterator, use iterator.remove()
* to avoid ConcurrentModificationExceptions. Use the boolean parameter to indicate the calling context.
*
- * @param fqn FQN of the removed node
* @throws EvictionException
*/
- protected void processRemovedNodes(Fqn fqn) throws EvictionException
+ protected void processRemovedNodes(EvictedEventNode evictedEventNode) throws EvictionException
{
+ Fqn fqn = evictedEventNode.getFqn();
+
if (log.isTraceEnabled())
{
log.trace("Removing node " + fqn + " from eviction queue and attempting eviction");
@@ -387,11 +389,11 @@
* into the queue. For some sorted collections, a remove, and a re-add is required to
* maintain the sorted order of the elements.
*
- * @param fqn FQN of the visited node.
* @throws EvictionException
*/
- protected void processVisitedNodes(Fqn fqn) throws EvictionException
+ protected void processVisitedNodes(EvictedEventNode evictedEventNode) throws EvictionException
{
+ Fqn fqn = evictedEventNode.getFqn();
NodeEntry ne = evictionQueue.getNodeEntry(fqn);
if (ne == null)
{
@@ -399,7 +401,7 @@
{
log.debug("Visiting node that was not added to eviction queues. Assuming that it has 1 element.");
}
- this.processAddedNodes(fqn, 1, false);
+ this.processAddedNodes(evictedEventNode, 1, false);
return;
}
// note this method will visit and modify the node statistics by reference!
@@ -409,8 +411,9 @@
ne.setModifiedTimeStamp(System.currentTimeMillis());
}
- protected void processRemovedElement(Fqn fqn) throws EvictionException
+ protected void processRemovedElement(EvictedEventNode evictedEventNode) throws EvictionException
{
+ Fqn fqn = evictedEventNode.getFqn();
NodeEntry ne = evictionQueue.getNodeEntry(fqn);
if (ne == null)
@@ -429,8 +432,9 @@
ne.setModifiedTimeStamp(System.currentTimeMillis());
}
- protected void processAddedElement(Fqn fqn) throws EvictionException
+ protected void processAddedElement(EvictedEventNode evictedEventNode) throws EvictionException
{
+ Fqn fqn = evictedEventNode.getFqn();
NodeEntry ne = evictionQueue.getNodeEntry(fqn);
if (ne == null)
{
@@ -438,7 +442,7 @@
{
log.trace("Adding element " + fqn + " for a node that doesn't exist yet. Process as an add.");
}
- this.processAddedNodes(fqn, 1, false);
+ this.processAddedNodes(evictedEventNode, 1, false);
return;
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/BaseSortedEvictionAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -46,22 +46,22 @@
switch (node.getEventType())
{
case ADD_NODE_EVENT:
- this.processAddedNodes(fqn, node.getElementDifference(), node.isResetElementCount());
+ this.processAddedNodes(node);
evictionNodesModified = true;
break;
case REMOVE_NODE_EVENT:
- this.processRemovedNodes(fqn);
+ this.processRemovedNodes(node);
break;
case VISIT_NODE_EVENT:
- this.processVisitedNodes(fqn);
+ this.processVisitedNodes(node);
evictionNodesModified = true;
break;
case ADD_ELEMENT_EVENT:
- this.processAddedElement(fqn);
+ this.processAddedElement(node);
evictionNodesModified = true;
break;
case REMOVE_ELEMENT_EVENT:
- this.processRemovedElement(fqn);
+ this.processRemovedElement(node);
evictionNodesModified = true;
break;
default:
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -29,15 +29,10 @@
ElementSizeConfiguration config = (ElementSizeConfiguration) region.getEvictionPolicyConfig();
int size = this.getEvictionQueue().getNumberOfNodes();
- if (config.getMaxNodes() != 0 && size > config.getMaxNodes())
- {
- return true;
- }
-
- return ne.getNumberOfElements() > config.getMaxElementsPerNode();
+ return config.getMaxNodes() != 0 && size > config.getMaxNodes() || ne.getNumberOfElements() > config.getMaxElementsPerNode();
}
-
+ @Override
protected void prune() throws EvictionException
{
super.prune();
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictedEventNode.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -23,6 +23,7 @@
private boolean resetElementCount_;
private long inUseTimeout;
+ private long creationTimestamp;
public EvictedEventNode(Fqn fqn, NodeEventType type, int elementDifference)
{
@@ -34,8 +35,14 @@
{
setFqn(fqn);
setEventType(event);
+ creationTimestamp = System.currentTimeMillis();
}
+ public long getCreationTimestamp()
+ {
+ return creationTimestamp;
+ }
+
public long getInUseTimeout()
{
return inUseTimeout;
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -163,9 +163,9 @@
Long ce = getExpiration(ee.getFqn());
if (ce == null || ce > ee.getExpiration())
{
- // Expiration now older
- i.remove();
- continue;
+ // Expiration now older
+ i.remove();
+ continue;
}
if (ee.getExpiration() < now || (max != 0 && set.size() > max))
{
@@ -179,8 +179,8 @@
}
if (max != 0 && max > set.size())
log.warn("Unable to remove nodes to reduce region size below " +
- config.getMaxNodes() + ". " +
- "Set expiration for nodes in this region");
+ config.getMaxNodes() + ". " +
+ "Set expiration for nodes in this region");
}
@Override
@@ -257,6 +257,7 @@
return fqn;
}
+ @Override
public boolean equals(Object o)
{
if (!(o instanceof ExpirationEntry))
@@ -265,11 +266,13 @@
return expiration == ee.expiration && fqn.equals(ee.fqn);
}
+ @Override
public int hashCode()
{
- return (int)expiration ^ fqn.hashCode();
+ return (int) expiration ^ fqn.hashCode();
}
+ @Override
public String toString()
{
long now = System.currentTimeMillis();
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -44,8 +44,6 @@
int size = this.getEvictionQueue().getNumberOfNodes();
return config.getMaxNodes() != 0 && size > config.getMaxNodes();
-
}
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -36,7 +36,6 @@
{
private static final Log log = LogFactory.getLog(LFUAlgorithm.class);
-
protected boolean shouldEvictNode(NodeEntry ne)
{
if (log.isTraceEnabled())
@@ -74,6 +73,7 @@
return new LFUQueue();
}
+ @Override
protected void prune() throws EvictionException
{
super.prune();
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -81,12 +81,11 @@
return false;
}
+ @Override
protected void evict(NodeEntry ne)
{
-// NodeEntry ne = evictionQueue.getNodeEntry(fqn);
if (ne != null)
{
-// evictionQueue.removeNodeEntry(ne);
if (!this.evictCacheNode(ne.getFqn()))
{
try
@@ -101,6 +100,7 @@
}
}
+ @Override
protected void prune() throws EvictionException
{
LRUQueue lruQueue = (LRUQueue) evictionQueue;
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java 2008-03-27 21:49:43 UTC (rev 5474)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithm.java 2008-03-28 15:43:37 UTC (rev 5475)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.eviction;
-import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
/**
@@ -32,14 +31,15 @@
// check the minimum time to live and see if we should not evict the node. This check will
// ensure that, if configured, nodes are kept alive for at least a minimum period of time.
if (isYoungerThanMinimumTimeToLive(ne)) return false;
-
+
MRUConfiguration config = (MRUConfiguration) region.getEvictionPolicyConfig();
return evictionQueue.getNumberOfNodes() > config.getMaxNodes();
}
- protected void processVisitedNodes(Fqn fqn) throws EvictionException
+ @Override
+ protected void processVisitedNodes(EvictedEventNode evictedEventNode) throws EvictionException
{
- super.processVisitedNodes(fqn);
- ((MRUQueue) evictionQueue).moveToTopOfStack(fqn);
+ super.processVisitedNodes(evictedEventNode);
+ ((MRUQueue) evictionQueue).moveToTopOfStack(evictedEventNode.getFqn());
}
}
16 years, 9 months
JBoss Cache SVN: r5474 - in core/tags/1.4.1.SP9: docs and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: jiwils
Date: 2008-03-27 17:49:43 -0400 (Thu, 27 Mar 2008)
New Revision: 5474
Modified:
core/tags/1.4.1.SP9/build.xml
core/tags/1.4.1.SP9/docs/Changelog.txt
core/tags/1.4.1.SP9/src/org/jboss/cache/Version.java
Log:
Changed the version/fix information for 1.4.1.SP9.
Modified: core/tags/1.4.1.SP9/build.xml
===================================================================
--- core/tags/1.4.1.SP9/build.xml 2008-03-27 21:38:16 UTC (rev 5473)
+++ core/tags/1.4.1.SP9/build.xml 2008-03-27 21:49:43 UTC (rev 5474)
@@ -6,7 +6,7 @@
<property name="module.name" value="JBossCache"/>
<!--We now requires version to have no white space since Ant+JBossAop will sometime choke. -->
- <property name="module.version" value="1.4.1.SP8"/>
+ <property name="module.version" value="1.4.1.SP9"/>
<property name="implementation.url" value="http://www.jboss.com/products/jbosscache"/>
<property file="build.properties"/>
<property name="root.dir" value="${basedir}"/>
@@ -81,7 +81,7 @@
<!-- See JBCACHE-814 -->
<exclude name="org/jboss/cache/eviction/ConcurrentEvictionTest*"/>
<exclude name="org/jboss/cache/passivation/ConcurrentPassivationTest*"/>
-
+
<!-- See JBCACHE-641 -->
<exclude name="org/jboss/cache/eviction/ReplicatedLRUPolicyTest*"/>
<!-- See JBCACHE-407 -->
@@ -795,10 +795,10 @@
<!-- Download the cache version against which we check interop -->
<mkdir dir="${output.interop.dir}"/>
-
+
<get dest="${output.interop.dir}/jboss-cache.jar"
src="http://repository.jboss.com/jboss/cache/1.2.3.1/lib/jboss-cache.jar" verbose="true"/>
- <!--
+ <!--
In 1.4.1 we moved to JG 2.4.1 by default, so we need to bring down the old jgroups as well.
The current.version.classpath and previous.version.classpath will use the old jgroups.
-->
Modified: core/tags/1.4.1.SP9/docs/Changelog.txt
===================================================================
--- core/tags/1.4.1.SP9/docs/Changelog.txt 2008-03-27 21:38:16 UTC (rev 5473)
+++ core/tags/1.4.1.SP9/docs/Changelog.txt 2008-03-27 21:49:43 UTC (rev 5474)
@@ -1,5 +1,14 @@
$Id$
+Release 1.4.1.SP9 (March 27. 2008)
+==================================
+Patch release on 1.4.1.GA
+
+** Bug
+ * [ JBCACHE-1246 ] TransactionTable leaks memory when used with FAIL_SILENTLY option
+ * [ JBCACHE-1292 ] Endless loop on concurrent remove
+ * [ JBCACHE-1255 ] setUseInterceptorMbeans not available in TreeCacheMBean interface, causing problems when deployed in JBoss AS
+
Release 1.4.1.SP8 (December 12, 2007)
=====================================
Patch release on 1.4.1.GA
@@ -57,7 +66,7 @@
* [ JBCACHE-1096 ] UpgradeException should print IdentityLock instances
* [ JBCACHE-1103 ] Make cache loader implementations thread safe and remove synchronization in CacheLoaderInterceptor and CacheStoreInterceptor
* [ JBCACHE-1114 ] StackOverflowError with Glassfish TransactionManager
- * [ JBCACHE-1139 ] Setting Option ineffective if CacheLoader or BuddyReplication is used
+ * [ JBCACHE-1139 ] Setting Option ineffective if CacheLoader or BuddyReplication is used
Release 1.4.1.SP3 (March 12, 2007)
=====================================
@@ -87,7 +96,7 @@
** Bug
* [ JBCACHE-974 ] Removing a parent node and then adding data to a child node in same tx causes endless loop
* [ JBCACHE-976 ] Correct docs to reflect LockParentForChildInsertRemove default is false
-
+
Release 1.4.1.SP1 (January 31, 2007)
====================================
Patch release on 1.4.1.GA
@@ -555,44 +564,44 @@
Release 1.2.4 (Oct 20 2005)
===========================
-* Create build examples for load and compile time instrumentation for JBossCacheAop
-* Support partial state transfer
+* Create build examples for load and compile time instrumentation for JBossCacheAop
+* Support partial state transfer
Details:
** Feature Request
-* [JBCACHE-265] - Create build examples for load and compile time instrumentation for JBossCacheAop
-* [JBCACHE-273] - Support partial state transfer
-* [JBCACHE-294] - Upgrade JRunitTests with Xref reporter
-* [JBCACHE-305] - Allow use of registerClassLoader() API before createService()/startService()
-* [JBCACHE-335] - Backwards Compatibility for State Transfer
+* [JBCACHE-265] - Create build examples for load and compile time instrumentation for JBossCacheAop
+* [JBCACHE-273] - Support partial state transfer
+* [JBCACHE-294] - Upgrade JRunitTests with Xref reporter
+* [JBCACHE-305] - Allow use of registerClassLoader() API before createService()/startService()
+* [JBCACHE-335] - Backwards Compatibility for State Transfer
** Bug
-* [JBCACHE-279] - JBossCache fails with java.util.NoSuchElementException under heavy logging load
-* [JBCACHE-292] - The specification info in the jboss-cache.jar manifest is incorrect.
-* [JBCACHE-293] - IdentityLock.releaseAll() attempts to modify an unmodifiable Set
-* [JBCACHE-298] - ReplicationInterceptor does not remove entries from transaction map for remote calls
-* [JBCACHE-303] - JDBCCacheLoader attempts JNDI lookup of DataSource before it is registered
-* [JBCACHE-308] - ReplicationInterceptor does not remove entries from remote_transactions set for one-phase commit calls
-* [JBCACHE-310] - IdentityLock.toString() not thread safe
-* [JBCACHE-316] - Deadlock problems with __JBoss_Internal__ region under REPL_SYNC
-* [JBCACHE-319] - Node marshalling marshalls data redundantly
-* [JBCACHE-329] - Optimistic locking - allows concurrent mod if a node is deleted in the underlying cache.
-* [JBCACHE-334] - JBossCacheAop deadlock if use putObject with shared pojos from two separate cache instances concurrently
-* [JBCACHE-343] - maxAgeSeconds in LRUPolicy is not set correctly
+* [JBCACHE-279] - JBossCache fails with java.util.NoSuchElementException under heavy logging load
+* [JBCACHE-292] - The specification info in the jboss-cache.jar manifest is incorrect.
+* [JBCACHE-293] - IdentityLock.releaseAll() attempts to modify an unmodifiable Set
+* [JBCACHE-298] - ReplicationInterceptor does not remove entries from transaction map for remote calls
+* [JBCACHE-303] - JDBCCacheLoader attempts JNDI lookup of DataSource before it is registered
+* [JBCACHE-308] - ReplicationInterceptor does not remove entries from remote_transactions set for one-phase commit calls
+* [JBCACHE-310] - IdentityLock.toString() not thread safe
+* [JBCACHE-316] - Deadlock problems with __JBoss_Internal__ region under REPL_SYNC
+* [JBCACHE-319] - Node marshalling marshalls data redundantly
+* [JBCACHE-329] - Optimistic locking - allows concurrent mod if a node is deleted in the underlying cache.
+* [JBCACHE-334] - JBossCacheAop deadlock if use putObject with shared pojos from two separate cache instances concurrently
+* [JBCACHE-343] - maxAgeSeconds in LRUPolicy is not set correctly
** Task
-* [JBCACHE-128] - Handle MashalledValue for different class loaders
-* [JBCACHE-138] - Release 1.2.4 final
-* [JBCACHE-296] - Incorporate Fix for JBAS-2262 in the jboss-system.jar bundled with JBossCache 1.2.4
-* [JBCACHE-299] - Update the build script to include a target that creates a dist with src
-* [JBCACHE-302] - Document using the TreeCacheMarshaller
-* [JBCACHE-304] - Added missing locking scheme apis for TreeCacheMBean
-* [JBCACHE-321] - Remove dependency on log4j
-* [JBCACHE-325] - Use NodeData instead of Externalizable to marshal transient state for state transfer
+* [JBCACHE-128] - Handle MashalledValue for different class loaders
+* [JBCACHE-138] - Release 1.2.4 final
+* [JBCACHE-296] - Incorporate Fix for JBAS-2262 in the jboss-system.jar bundled with JBossCache 1.2.4
+* [JBCACHE-299] - Update the build script to include a target that creates a dist with src
+* [JBCACHE-302] - Document using the TreeCacheMarshaller
+* [JBCACHE-304] - Added missing locking scheme apis for TreeCacheMBean
+* [JBCACHE-321] - Remove dependency on log4j
+* [JBCACHE-325] - Use NodeData instead of Externalizable to marshal transient state for state transfer
Release 1.2.4Beta (Spet 12 2005)
Modified: core/tags/1.4.1.SP9/src/org/jboss/cache/Version.java
===================================================================
--- core/tags/1.4.1.SP9/src/org/jboss/cache/Version.java 2008-03-27 21:38:16 UTC (rev 5473)
+++ core/tags/1.4.1.SP9/src/org/jboss/cache/Version.java 2008-03-27 21:49:43 UTC (rev 5474)
@@ -10,9 +10,9 @@
*/
public class Version
{
- public static final String version = "1.4.1.SP8";
+ public static final String version = "1.4.1.SP9";
public static final String codename = "Cayenne";
- public static byte[] version_id = {'0', '1', '4', '1', 'S', 'P', '8'};
+ public static byte[] version_id = {'0', '1', '4', '1', 'S', 'P', '9'};
public static final String cvs = "$Id$";
private static final int MAJOR_SHIFT = 11;
16 years, 9 months
JBoss Cache SVN: r5473 - core/tags.
by jbosscache-commits@lists.jboss.org
Author: jiwils
Date: 2008-03-27 17:38:16 -0400 (Thu, 27 Mar 2008)
New Revision: 5473
Added:
core/tags/1.4.1.SP9/
Log:
Cut from 1.4.X of 1.4.1.SP9.
Copied: core/tags/1.4.1.SP9 (from rev 5472, core/branches/1.4.X)
16 years, 9 months
JBoss Cache SVN: r5472 - experimental/jsr166/src/jsr166y.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-03-27 17:26:02 -0400 (Thu, 27 Mar 2008)
New Revision: 5472
Modified:
experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java
Log:
Update docs, test
Modified: experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
===================================================================
--- experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java 2008-03-27 21:03:09 UTC (rev 5471)
+++ experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java 2008-03-27 21:26:02 UTC (rev 5472)
@@ -64,7 +64,7 @@
* non-strong values may disappear before their corresponding key.
*
* While this table does allow the use of both strong keys and values, it is
- * recommended to use {@link java.util.concurrent.ConcurrentHashMap} for this
+ * recommended to use {@link java.util.concurrent.ConcurrentHashMap} for such a
* configuration, since it is optimized for that case.
*
* Just like {@link java.util.concurrent.ConcurrentHashMap}, this class obeys
@@ -1260,7 +1260,15 @@
}
/**
- * Removes any entries, whose keys have been finalized
+ * Removes any stale entries whose keys have been finalized. Use of this
+ * method is normally not necessary since stale entries are automatically
+ * removed lazily, when blocking operations are required. However, there
+ * are some cases where this operation should be performed eagerly, such
+ * as cleaning up old references to a ClassLoader in a multi-classloader
+ * environment.
+ *
+ * Note: this method will acquire locks, one at a time, across all segments
+ * of this table, so if it is to be used, it should be used sparingly.
*/
public void purgeStaleEntries() {
for (int i = 0; i < segments.length; ++i)
Modified: experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java
===================================================================
--- experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java 2008-03-27 21:03:09 UTC (rev 5471)
+++ experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java 2008-03-27 21:26:02 UTC (rev 5472)
@@ -1,24 +1,68 @@
package jsr166y;
-import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
-import jsr166y.ConcurrentReferenceHashMap.Option;
import jsr166y.ConcurrentReferenceHashMap.ReferenceType;
import junit.framework.TestCase;
public class ConcurrentReferenceHashMapGCTestCase extends TestCase {
- public void testBasicCleanup() throws Exception {
+ public void testWeakCleanup() throws Exception {
+ basicCleanup(false);
+ }
+
+ public void testWeakIterators() throws Exception {
+ iterators(false);
+ }
+
+ public void testSoftCleanup() throws Exception {
+ basicCleanup(true);
+ }
+
+ public void testSoftIterators() throws Exception {
+ iterators(true);
+ }
+
+ public void testSoftValues() throws Exception {
+ values(true);
+ }
+
+ public void testWeakValues() throws Exception {
+ values(false);
+ }
+
+ private void values(boolean soft) throws Exception {
+ ConcurrentReferenceHashMap<String, Integer> map =
+ new ConcurrentReferenceHashMap<String, Integer>(16,
+ ReferenceType.STRONG,
+ soft ? ReferenceType.SOFT : ReferenceType.WEAK);
+
+ Integer i = 5;
+ map.put("five", i);
+ map.put("one", new Integer(1));
+ assertEquals(2, map.size());
+ assertEquals(i, map.get("five"));
+ assertEquals(new Integer(1), map.get("one"));
+
+ gc(soft);
+ assertEquals(2, map.size());
+ assertEquals(i, map.get("five"));
+ assertTrue(map.containsKey("one"));
+ assertNull(map.get("one"));
+ }
+
+ private void basicCleanup(boolean soft) throws Exception {
ConcurrentReferenceHashMap<BinClump, Integer> map =
- new ConcurrentReferenceHashMap<BinClump, Integer>(0, .75f, 16, ReferenceType.SOFT, ReferenceType.STRONG, null);
+ new ConcurrentReferenceHashMap<BinClump, Integer>(16,
+ soft ? ReferenceType.SOFT : ReferenceType.WEAK,
+ ReferenceType.STRONG);
BinClump[] hold = new BinClump[100];
generateClumps(map, hold, 10000);
- gc();
- Thread.sleep(1000);
+ gc(soft);
+ Thread.sleep(500);
// trigger a cleanup without matching any key
for (int i = 0; i < 100; i++)
@@ -27,12 +71,14 @@
assertEquals(100, map.size());
}
- public void testIterators() throws Exception {
+ private void iterators(boolean soft) throws Exception {
ConcurrentReferenceHashMap<BinClump, Integer> map =
- new ConcurrentReferenceHashMap<BinClump, Integer>(0, .75f, 16, ReferenceType.SOFT, ReferenceType.STRONG, null);
+ new ConcurrentReferenceHashMap<BinClump, Integer>(16,
+ soft ? ReferenceType.SOFT : ReferenceType.WEAK,
+ ReferenceType.STRONG);
BinClump[] hold = new BinClump[100];
generateClumps(map, hold, 10000);
- gc();
+ gc(soft);
Thread.sleep(500);
// Stale entries are not yet cleared
@@ -67,11 +113,10 @@
// Should be stale free now
assertEquals(100, map.size());
Iterator<BinClump> i = map.keySet().iterator();
- while (i.hasNext() && i.next() != hold[0])
- ;
+ while (i.hasNext() && i.next() != hold[0]);
hold = null;
- gc();
+ gc(soft);
Thread.sleep(500);
// trigger a cleanup without matching any key
@@ -83,7 +128,7 @@
// Free iterator
i = null;
- gc();
+ gc(soft);
Thread.sleep(500);
// trigger a cleanup without matching any key
@@ -94,16 +139,21 @@
}
- private void gc() {
+ private void gc(boolean soft) {
System.gc();
- int chunkSize = (int) Math.min(Runtime.getRuntime().maxMemory() / 16, Integer.MAX_VALUE);
- try {
- LinkedList<long[]> list = new LinkedList<long[]>();
- for (;;)
- list.add(new long[chunkSize]);
- } catch (OutOfMemoryError e)
- {}
- System.gc();
+
+ if (soft) {
+ int chunkSize = (int) Math.min(
+ Runtime.getRuntime().maxMemory() / 16, Integer.MAX_VALUE);
+ try {
+ LinkedList<long[]> list = new LinkedList<long[]>();
+ for (;;)
+ list.add(new long[chunkSize]);
+ } catch (OutOfMemoryError e) {
+ }
+
+ System.gc();
+ }
}
private void generateClumps(ConcurrentReferenceHashMap<BinClump, Integer> map,
16 years, 9 months
JBoss Cache SVN: r5471 - experimental/jsr166/src/jsr166y.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-03-27 17:03:09 -0400 (Thu, 27 Mar 2008)
New Revision: 5471
Modified:
experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
Log:
Update docs
Modified: experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
===================================================================
--- experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java 2008-03-27 17:09:21 UTC (rev 5470)
+++ experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java 2008-03-27 21:03:09 UTC (rev 5471)
@@ -20,6 +20,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -27,9 +28,17 @@
import java.util.concurrent.locks.ReentrantLock;
/**
- * A hash table with <em>weak keys</em>, full concurrency of retrievals, and
- * adjustable expected concurrency for updates. Similar to
- * {@link java.util.WeakHashMap}, entries of this table are periodically
+ * An advanced hash table supporting configurable garbage collection semantics
+ * of keys and values, optional referential-equality, full concurrency of
+ * retrievals, and adjustable expected concurrency for updates.
+ *
+ * This table is designed around specific advanced use-cases. If there is any
+ * doubt whether this table is for you, you most likely should be using
+ * {@link java.util.concurrent.ConcurrentHashMap} instead.
+ *
+ * This table supports strong, weak, and soft keys and values. By default keys
+ * are weak, and values are strong. Such a configuration offers similar behavior
+ * to {@link java.util.WeakHashMap}, entries of this table are periodically
* removed once their corresponding keys are no longer referenced outside of
* this table. In other words, this table will not prevent a key from being
* discarded by the garbage collector. Once a key has been discarded by the
@@ -40,23 +49,34 @@
* entries. In order to support a high level of concurrency, stale entries are
* only reclaimed during blocking (usually mutating) operations.
*
- * While keys in this table are only held using a weak reference, values are
- * held using a normal strong reference. This provides the guarantee that a
- * value will always have at least the same life-span as it's key. For this
- * reason, care should be taken to ensure that a value never refers, either
- * directly or indirectly, to its key, thereby preventing reclamation. If weak
- * values are desired, one can simply use a {@link WeakReference} for the value
- * type.
+ * Enabling soft keys allows entries in this table to remain until their space
+ * is absolutely needed by the garbage collector. This is unlike weak keys which
+ * can be reclaimed as soon as they are no longer referenced by a normal strong
+ * reference. The primary use case for soft keys is a cache, which ideally
+ * occupies memory that is not in use for as long as possible.
*
- * Just like {@link java.util.ConcurrentHashMap}, this class obeys the same
- * functional specification as {@link java.util.Hashtable}, and includes
- * versions of methods corresponding to each method of <tt>Hashtable</tt>.
- * However, even though all operations are thread-safe, retrieval operations do
- * <em>not</em> entail locking, and there is <em>not</em> any support for
- * locking the entire table in a way that prevents all access. This class is
- * fully interoperable with <tt>Hashtable</tt> in programs that rely on its
- * thread safety but not on its synchronization details.
+ * By default, values are held using a normal strong reference. This provides
+ * the commonly desired guarantee that a value will always have at least the
+ * same life-span as it's key. For this reason, care should be taken to ensure
+ * that a value never refers, either directly or indirectly, to its key, thereby
+ * preventing reclamation. If this is unavoidable, then it is recommended to use
+ * the same reference type in use for the key. However, it should be noted that
+ * non-strong values may disappear before their corresponding key.
*
+ * While this table does allow the use of both strong keys and values, it is
+ * recommended to use {@link java.util.concurrent.ConcurrentHashMap} for this
+ * configuration, since it is optimized for that case.
+ *
+ * Just like {@link java.util.concurrent.ConcurrentHashMap}, this class obeys
+ * the same functional specification as {@link java.util.Hashtable}, and
+ * includes versions of methods corresponding to each method of
+ * <tt>Hashtable</tt>. However, even though all operations are thread-safe,
+ * retrieval operations do <em>not</em> entail locking, and there is
+ * <em>not</em> any support for locking the entire table in a way that
+ * prevents all access. This class is fully interoperable with
+ * <tt>Hashtable</tt> in programs that rely on its thread safety but not on
+ * its synchronization details.
+ *
* <p>
* Retrieval operations (including <tt>get</tt>) generally do not block, so
* may overlap with update operations (including <tt>put</tt> and
@@ -113,10 +133,26 @@
* each of which itself is a concurrently readable hash table.
*/
- public static enum ReferenceType {STRONG, WEAK, SOFT};
+ /**
+ * An option specifying which Java reference type should be used to refer
+ * to a key and/or value.
+ */
+ public static enum ReferenceType {
+ /** Indicates a normal Java strong reference should be used */
+ STRONG,
+ /** Indicates a {@link WeakReference} should be used */
+ WEAK,
+ /** Indicates a {@link SoftReference} should be used */
+ SOFT
+ };
- public static enum Option {IDENTITY_COMPARISONS};
+ public static enum Option {
+ /** Indicates that referential-equality (== instead of .equals()) should
+ * be used when locating keys. This offers similar behavior to {@link IdentityHashMap} */
+ IDENTITY_COMPARISONS
+ };
+
/* ---------------- Constants -------------- */
static final ReferenceType DEFAULT_KEY_TYPE = ReferenceType.WEAK;
@@ -193,7 +229,7 @@
/**
* Applies a supplemental hash function to a given hashCode, which
* defends against poor quality hash functions. This is critical
- * because ConcurrentWeakHashMap uses power-of-two length hash tables,
+ * because ConcurrentReferenceHashMap uses power-of-two length hash tables,
* that otherwise encounter collisions for hashCodes that do not
* differ in lower or upper bits.
*/
@@ -257,7 +293,7 @@
}
/**
- * ConcurrentWeakHashMap list entry. Note that this is never exported
+ * ConcurrentReferenceHashMap list entry. Note that this is never exported
* out as a user-visible Map.Entry.
*
* Because the value field is volatile, not final, it is legal wrt
@@ -767,7 +803,10 @@
/**
* Creates a new, empty map with the specified initial
- * capacity, load factor and concurrency level.
+ * capacity, reference types, load factor and concurrency level.
+ *
+ * Behavioral changing options such as {@link Option#IDENTITY_COMPARISONS}
+ * can also be specified.
*
* @param initialCapacity the initial capacity. The implementation
* performs internal sizing to accommodate this many elements.
@@ -777,6 +816,9 @@
* @param concurrencyLevel the estimated number of concurrently
* updating threads. The implementation performs internal sizing
* to try to accommodate this many threads.
+ * @param keyType the reference type to use for keys
+ * @param valueType the reference type to use for values
+ * @param options the behavioral options
* @throws IllegalArgumentException if the initial capacity is
* negative or the load factor or concurrencyLevel are
* nonpositive.
@@ -842,7 +884,8 @@
/**
* Creates a new, empty map with the specified initial capacity
- * and load factor and with the default concurrencyLevel (16).
+ * and load factor and with the default reference types (weak keys,
+ * strong values), and concurrencyLevel (16).
*
* @param initialCapacity The implementation performs internal
* sizing to accommodate this many elements.
@@ -858,9 +901,28 @@
this(initialCapacity, loadFactor, DEFAULT_CONCURRENCY_LEVEL);
}
+
/**
+ * Creates a new, empty map with the specified initial capacity,
+ * reference types and with default load factor (0.75) and concurrencyLevel (16).
+ *
+ * @param initialCapacity the initial capacity. The implementation
+ * performs internal sizing to accommodate this many elements.
+ * @param keyType the reference type to use for keys
+ * @param valueType the reference type to use for values
+ * @throws IllegalArgumentException if the initial capacity of
+ * elements is negative.
+ */
+ public ConcurrentReferenceHashMap(int initialCapacity,
+ ReferenceType keyType, ReferenceType valueType) {
+ this(initialCapacity, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL,
+ keyType, valueType, null);
+ }
+
+ /**
* Creates a new, empty map with the specified initial capacity,
- * and with default load factor (0.75) and concurrencyLevel (16).
+ * and with default reference types (weak keys, strong values),
+ * load factor (0.75) and concurrencyLevel (16).
*
* @param initialCapacity the initial capacity. The implementation
* performs internal sizing to accommodate this many elements.
@@ -873,6 +935,7 @@
/**
* Creates a new, empty map with a default initial capacity (16),
+ * reference types (weak keys, strong values), default
* load factor (0.75) and concurrencyLevel (16).
*/
public ConcurrentReferenceHashMap() {
@@ -1195,6 +1258,15 @@
for (int i = 0; i < segments.length; ++i)
segments[i].clear();
}
+
+ /**
+ * Removes any entries, whose keys have been finalized
+ */
+ public void purgeStaleEntries() {
+ for (int i = 0; i < segments.length; ++i)
+ segments[i].removeStale();
+ }
+
/**
* Returns a {@link Set} view of the keys contained in this map.
@@ -1533,7 +1605,7 @@
/* ---------------- Serialization Support -------------- */
/**
- * Save the state of the <tt>ConcurrentWeakHashMap</tt> instance to a
+ * Save the state of the <tt>ConcurrentReferenceHashMap</tt> instance to a
* stream (i.e., serialize it).
* @param s the stream
* @serialData
@@ -1568,7 +1640,7 @@
}
/**
- * Reconstitute the <tt>ConcurrentWeakHashMap</tt> instance from a
+ * Reconstitute the <tt>ConcurrentReferenceHashMap</tt> instance from a
* stream (i.e., deserialize it).
* @param s the stream
*/
16 years, 9 months