Author: manik.surtani(a)jboss.com
Date: 2008-08-18 09:34:16 -0400 (Mon, 18 Aug 2008)
New Revision: 6574
Added:
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionWatcher.java
Modified:
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueueList.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/MRUQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionQueue.java
core/trunk/src/main/java/org/jboss/cache/jmx/ResourceDMBean.java
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeQueueTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUQueueTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java
core/trunk/src/test/resources/configs/string-property-replaced.xml
Log:
Updated eviction code and tests
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-08-18 13:34:16
UTC (rev 6574)
@@ -8,7 +8,6 @@
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionAlgorithmConfig;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
@@ -93,20 +92,20 @@
public void start()
{
if (trace) log.trace("Starting region manager");
- isUsingBR = configuration.getBuddyReplicationConfig() != null &&
configuration.getBuddyReplicationConfig().isEnabled();
+ isUsingBR = configuration != null &&
configuration.getBuddyReplicationConfig() != null &&
configuration.getBuddyReplicationConfig().isEnabled();
evictionConfig = configuration.getEvictionConfig();
if (evictionConfig != null && evictionConfig.isValidConfig())
{
+ this.evictionConfig = configuration.getEvictionConfig();
// start with the default region
EvictionRegionConfig defaultRegion =
configuration.getEvictionConfig().getDefaultEvictionRegionConfig();
- defaultRegion.getEvictionAlgorithmConfig().validate();
+ if (defaultRegion.getEvictionAlgorithmConfig() != null)
defaultRegion.getEvictionAlgorithmConfig().validate();
// validate individual region configs now
for (EvictionRegionConfig erc :
configuration.getEvictionConfig().getEvictionRegionConfigs())
{
evictionConfig.applyDefaults(erc);
- EvictionAlgorithmConfig eac = erc.getEvictionAlgorithmConfig();
- if (eac != null) eac.validate();
+ erc.validate();
}
setEvictionConfig(configuration.getEvictionConfig());
@@ -704,8 +703,6 @@
public void setEvictionConfig(EvictionConfig evictionConfig)
{
- this.evictionConfig = evictionConfig;
-
// JBAS-1288
// Try to establish a default region if there isn't one already
// boolean needDefault;
@@ -714,7 +711,9 @@
// contrary to the idea that there *must* be a default region, but some
// unit tests fail w/ APPROACH 1, so for now we go with this approach.
// needDefault = ercs.size() == 0;
- ercs.add(0, evictionConfig.getDefaultEvictionRegionConfig());
+ if (evictionConfig.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig() !=
null &&
+ !ercs.contains(evictionConfig.getDefaultEvictionRegionConfig())) // then the
default is a real region too; not just a template for others
+ ercs.add(0, evictionConfig.getDefaultEvictionRegionConfig());
// if (needDefault)
// {
// // This may throw ConfigurationException if there is no default
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -246,7 +246,9 @@
if (evictionRegionConfigs != null)
{
// needs to be a deep copy
- for (EvictionRegionConfig erc : evictionRegionConfigs)
clone.addEvictionRegionConfig(erc.clone());
+ clone.evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
+ for (EvictionRegionConfig erc : evictionRegionConfigs)
+ clone.addEvictionRegionConfig(erc.clone());
}
return clone;
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -78,6 +78,13 @@
this.evictionAlgorithmConfig = evictionAlgorithmConfig;
}
+ public EvictionRegionConfig(Fqn regionFqn, EvictionAlgorithmConfig
evictionAlgorithmConfig, int queueSize)
+ {
+ this.regionFqn = regionFqn;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ this.eventQueueSize = queueSize;
+ }
+
public EvictionRegionConfig(Fqn fqn)
{
this.regionFqn = fqn;
@@ -284,4 +291,18 @@
{
if (this.eventQueueSize == null) this.eventQueueSize = eventQueueSize;
}
+
+ /**
+ * Ensure this is a valid eviction region configuration.
+ */
+ public void validate()
+ {
+ if (eventQueueSize < 1)
+ throw new ConfigurationException("Eviction event queue size cannot be less
than 1!");
+
+ if (evictionAlgorithmConfig == null)
+ throw new MissingPolicyException("Eviction algorithm configuration cannot
be null!");
+
+ evictionAlgorithmConfig.validate();
+ }
}
\ No newline at end of file
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -176,7 +176,7 @@
throw new OldFileFormatException();
}
- if (! "jbosscache".equals(root.getLocalName()) || !
JBOSSCACHE_CORE_NS.equals(root.getNamespaceURI()))
+ if (!"jbosscache".equals(root.getLocalName()) ||
!JBOSSCACHE_CORE_NS.equals(root.getNamespaceURI()))
throw new ConfigurationException("Expected root element {" +
JBOSSCACHE_CORE_NS + "}" + "jbosscache");
}
@@ -200,7 +200,7 @@
}
catch (Exception e)
{
- throw new ConfigurationException("Unexpected excetion while parsing the
configuration file", e);
+ throw new ConfigurationException("Unexpected exception while parsing the
configuration file", e);
}
return config;
}
Modified:
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -146,7 +146,7 @@
if (eac != null)
{
- parseEvictionPolicyConfig(element, eac, defaultRegion != null);
+ parseEvictionPolicyConfig(element, eac);
erc.setEvictionAlgorithmConfig(eac);
}
@@ -166,12 +166,11 @@
return erc;
}
- public static void parseEvictionPolicyConfig(Element element, EvictionAlgorithmConfig
target, boolean validate)
+ public static void parseEvictionPolicyConfig(Element element, EvictionAlgorithmConfig
target)
{
target.reset();
ParsedAttributes attributes = XmlConfigHelper.extractAttributes(element);
XmlConfigHelper.setValues(target, attributes.stringAttribs, false, true);
XmlConfigHelper.setValues(target, attributes.xmlAttribs, true, true);
- if (validate) target.validate();
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -71,13 +71,16 @@
recycleQueue = new LinkedBlockingQueue<Fqn>(500000);
}
- public void initialize()
+ public synchronized void initialize()
{
- evictionQueue = setupEvictionQueue();
- if (log.isDebugEnabled()) log.debug("Initialized: " + this);
- Configuration.CacheMode cm = configuration != null ? configuration.getCacheMode() :
Configuration.CacheMode.LOCAL;
- allowTombstones = configuration != null &&
configuration.getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC &&
- (cm == Configuration.CacheMode.INVALIDATION_ASYNC || cm ==
Configuration.CacheMode.INVALIDATION_SYNC);
+ if (evictionQueue == null)
+ {
+ evictionQueue = setupEvictionQueue();
+ if (log.isDebugEnabled()) log.debug("Initialized: " + this);
+ Configuration.CacheMode cm = configuration != null ?
configuration.getCacheMode() : Configuration.CacheMode.LOCAL;
+ allowTombstones = configuration != null &&
configuration.getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC &&
+ (cm == Configuration.CacheMode.INVALIDATION_ASYNC || cm ==
Configuration.CacheMode.INVALIDATION_SYNC);
+ }
}
public EvictionActionPolicy getEvictionActionPolicy()
@@ -121,6 +124,7 @@
public void process(BlockingQueue<EvictionEvent> eventQueue) throws
EvictionException
{
if (trace) log.trace("process(): region: " + regionFqn);
+ initialize();
this.processQueues(eventQueue);
this.emptyRecycleQueue();
this.prune();
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/DefaultEvictionActionPolicy.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -25,6 +25,7 @@
{
try
{
+ if (log.isTraceEnabled()) log.trace("Evicting Fqn " + fqn);
cache.evict(fqn);
return true;
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithm.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -28,7 +28,7 @@
if (isYoungerThanMinimumTimeToLive(ne)) return false;
int size = this.getEvictionQueue().getNumberOfNodes();
ElementSizeAlgorithmConfig config = (ElementSizeAlgorithmConfig)
evictionAlgorithmConfig;
- return config.getMaxNodes() != 0 && size > config.getMaxNodes() ||
ne.getNumberOfElements() > config.getMaxElementsPerNode();
+ return config.getMaxNodes() > -1 && size > config.getMaxNodes() ||
ne.getNumberOfElements() > config.getMaxElementsPerNode();
}
@Override
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeAlgorithmConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -59,6 +59,7 @@
@Override
public void validate() throws ConfigurationException
{
+ super.validate();
if (maxElementsPerNode < 0)
{
throw new ConfigurationException("maxElementsPerNode must be must be "
+
@@ -100,6 +101,7 @@
{
super.reset();
setMaxElementsPerNode(-1);
+ evictionAlgorithmClassName = ElementSizeAlgorithm.class.getName();
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -8,7 +8,16 @@
import org.jboss.cache.Fqn;
-import java.util.*;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
/**
* @author Daniel Huang
@@ -154,7 +163,7 @@
}
}
- public Iterator<NodeEntry> iterate()
+ public Iterator<NodeEntry> iterator()
{
return evictionList.iterator();
}
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionAlgorithmConfigBase.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -71,7 +71,8 @@
public void validate() throws ConfigurationException
{
- // no-op
+ if (evictionAlgorithmClassName == null)
+ throw new ConfigurationException("Eviction algorithm class name cannot be
null!");
}
public boolean equals(Object o)
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueue.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueue.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -8,9 +8,7 @@
import org.jboss.cache.Fqn;
-import java.util.Iterator;
-
/**
* Eviction Queue interface defines a contract for the Eviction Queue implementations
used by EvictionPolicies.
* <p/>
@@ -20,7 +18,7 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision$
*/
-public interface EvictionQueue
+public interface EvictionQueue extends Iterable<NodeEntry>
{
/**
* Get the first entry in the queue.
@@ -85,8 +83,6 @@
void modifyElementCount(int difference);
- Iterator iterate();
-
/**
* Clear the queue.
*/
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueueList.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueueList.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionQueueList.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -134,7 +134,7 @@
return tail;
}
- Iterator iterator()
+ Iterator<NodeEntry> iterator()
{
return new EvictionListIterator();
}
@@ -231,7 +231,7 @@
}
}
- class EvictionListIterator implements ListIterator
+ class EvictionListIterator implements ListIterator<NodeEntry>
{
EvictionListEntry next = head;
EvictionListEntry previous;
@@ -245,7 +245,7 @@
return next != null;
}
- public Object next()
+ public NodeEntry next()
{
this.doConcurrentModCheck();
this.forwardCursor();
@@ -258,7 +258,7 @@
return previous != null;
}
- public Object previous()
+ public NodeEntry previous()
{
this.doConcurrentModCheck();
this.rewindCursor();
@@ -287,13 +287,13 @@
initialModCount++;
}
- public void set(Object o)
+ public void set(NodeEntry o)
{
this.doConcurrentModCheck();
cursor.node = (NodeEntry) o;
}
- public void add(Object o)
+ public void add(NodeEntry o)
{
this.doConcurrentModCheck();
initialModCount++;
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithm.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -338,7 +338,7 @@
return set.size();
}
- public Iterator iterate()
+ public Iterator<NodeEntry> iterator()
{
return null;
}
Modified:
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationAlgorithmConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -120,4 +120,13 @@
result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
return result;
}
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ evictionAlgorithmClassName = ExpirationAlgorithm.class.getName();
+ warnNoExpirationKey = true;
+ timeToLive = 0;
+ }
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithmConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -44,6 +44,7 @@
@Override
public void validate() throws ConfigurationException
{
+ super.validate();
if (getMaxNodes() < 0)
{
throw new ConfigurationException("maxNodes must be must be " +
@@ -68,7 +69,9 @@
@Override
public void reset()
{
+ super.reset();
setMaxNodes(-1);
+ evictionAlgorithmClassName = FIFOAlgorithm.class.getName();
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOQueue.java 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOQueue.java 2008-08-18 13:34:16
UTC (rev 6574)
@@ -101,7 +101,7 @@
this.numElements = 0;
}
- public Iterator<NodeEntry> iterate()
+ public Iterator<NodeEntry> iterator()
{
return nodeMap.values().iterator();
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -51,7 +51,7 @@
LFUAlgorithmConfig config = (LFUAlgorithmConfig) evictionAlgorithmConfig;
int size = this.getEvictionQueue().getNumberOfNodes();
- if (config.getMaxNodes() != 0 && size > config.getMaxNodes())
+ if (config.getMaxNodes() > -1 && size > config.getMaxNodes())
{
return true;
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithmConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -78,4 +78,12 @@
{
return (LFUAlgorithmConfig) super.clone();
}
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ minNodes = -1;
+ evictionAlgorithmClassName = LFUAlgorithm.class.getName();
+ }
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java 2008-08-18 13:34:16
UTC (rev 6574)
@@ -8,7 +8,16 @@
import org.jboss.cache.Fqn;
-import java.util.*;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
/**
* LFUQueue EvictionQueue implementation for LFU Policy.
@@ -143,7 +152,7 @@
protected void prune()
{
- Iterator<NodeEntry> it = this.iterate();
+ Iterator<NodeEntry> it = this.iterator();
while (it.hasNext() && removalQueue.size() > 0)
{
if (removalQueue.remove(it.next()))
@@ -163,7 +172,7 @@
return this.removalQueue;
}
- public Iterator<NodeEntry> iterate()
+ public Iterator<NodeEntry> iterator()
{
return evictionList.iterator();
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -40,10 +40,10 @@
LRUAlgorithmConfig config = (LRUAlgorithmConfig) evictionAlgorithmConfig;
// no idle or max time limit
- if (config.getTimeToLive() == 0 && config.getMaxAge() == 0) return false;
+ if (config.getTimeToLive() < 0 && config.getMaxAge() < 0) return
false;
long currentTime = System.currentTimeMillis();
- if (config.getTimeToLive() != 0)
+ if (config.getTimeToLive() > -1)
{
long idleTime = currentTime - entry.getModifiedTimeStamp();
if (trace)
@@ -62,7 +62,7 @@
}
}
- if (config.getMaxAge() != 0)
+ if (config.getMaxAge() > -1)
{
long objectLifeTime = currentTime - entry.getCreationTimeStamp();
if (trace)
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithmConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -42,6 +42,7 @@
evictionAlgorithmClassName = LRUAlgorithm.class.getName();
// Force config of ttls
setTimeToLive(-1);
+ setMaxAge(-1);
}
public LRUAlgorithmConfig(long timeToLive, long maxAge)
@@ -51,7 +52,7 @@
this.maxAge = maxAge;
}
- public LRUAlgorithmConfig(int timeToLive, int maxAge, int maxNodes)
+ public LRUAlgorithmConfig(long timeToLive, int maxAge, int maxNodes)
{
this(timeToLive, maxAge);
this.maxNodes = maxNodes;
@@ -114,16 +115,18 @@
@Override
public void validate() throws ConfigurationException
{
- if (timeToLive < 0)
+ super.validate();
+ if (timeToLive < -1)
{
throw new ConfigurationException("timeToLive must be " +
- "configured to a value greater than or equal to 0 for " +
getEvictionAlgorithmClassName());
+ "configured to a value greater than or equal to 0 (or -1 for
unlimited time to live) for " + getEvictionAlgorithmClassName());
}
}
public String toString()
{
return "LRUAlgorithmConfig {" +
+ "algorithmClassName=" + evictionAlgorithmClassName +
", timeToLive=" + timeToLive +
", maxAge=" + maxAge +
'}';
@@ -156,6 +159,8 @@
{
super.reset();
setTimeToLive(-1);
+ setMaxAge(-1);
+ evictionAlgorithmClassName = LRUAlgorithm.class.getName();
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUQueue.java 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUQueue.java 2008-08-18 13:34:16
UTC (rev 6574)
@@ -170,7 +170,7 @@
this.numElements += difference;
}
- public Iterator<NodeEntry> iterate()
+ public Iterator<NodeEntry> iterator()
{
return lruQueue.values().iterator();
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUAlgorithmConfig.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -43,6 +43,7 @@
@Override
public void validate() throws ConfigurationException
{
+ super.validate();
if (getMaxNodes() < 0)
throw new ConfigurationException("maxNodes not configured");
}
@@ -65,7 +66,9 @@
@Override
public void reset()
{
+ super.reset();
setMaxNodes(-1);
+ evictionAlgorithmClassName = MRUAlgorithm.class.getName();
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/MRUQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/MRUQueue.java 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/MRUQueue.java 2008-08-18 13:34:16
UTC (rev 6574)
@@ -141,7 +141,7 @@
this.numElements = 0;
}
- public Iterator iterate()
+ public Iterator<NodeEntry> iterator()
{
return list.iterator();
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionQueue.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/NullEvictionQueue.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -1,23 +1,25 @@
/**
- *
+ *
*/
package org.jboss.cache.eviction;
+import org.jboss.cache.Fqn;
+
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.jboss.cache.Fqn;
-
/**
* A queue that does nothing.
- *
+ *
* @author Brian Stansberry
*/
public class NullEvictionQueue implements EvictionQueue
{
- /** Singleton instance of this class. */
+ /**
+ * Singleton instance of this class.
+ */
public static final NullEvictionQueue INSTANCE = new NullEvictionQueue();
-
+
/**
* Constructs a new NullEvictionQueue.
*/
@@ -25,87 +27,109 @@
{
}
- /** No-op */
+ /**
+ * No-op
+ */
public void addNodeEntry(NodeEntry entry)
{
// no-op
}
- /** No-op */
+ /**
+ * No-op
+ */
public void clear()
{
// no-op
}
- /** Returns <code>false</code> */
+ /**
+ * Returns <code>false</code>
+ */
public boolean containsNodeEntry(NodeEntry entry)
{
return false;
}
- /** Returns <code>null</code> */
+ /**
+ * Returns <code>null</code>
+ */
public NodeEntry getFirstNodeEntry()
{
return null;
}
- /** Returns <code>null</code> */
+ /**
+ * Returns <code>null</code>
+ */
public NodeEntry getNodeEntry(Fqn fqn)
{
return null;
}
- /** Returns <code>null</code> */
+ /**
+ * Returns <code>null</code>
+ */
public NodeEntry getNodeEntry(String fqn)
{
return null;
}
- /** Returns <code>0</code> */
+ /**
+ * Returns <code>0</code>
+ */
public int getNumberOfElements()
{
return 0;
}
- /** Returns <code>0</code> */
+ /**
+ * Returns <code>0</code>
+ */
public int getNumberOfNodes()
{
return 0;
}
- /**
+ /**
* Returns an <code>Iterator</code> whose
* <code>hasNext()</code> returns <code>false</code>.
*/
- public Iterator iterate()
+ public Iterator<NodeEntry> iterator()
{
return NullQueueIterator.INSTANCE;
}
- /** No-op */
+ /**
+ * No-op
+ */
public void modifyElementCount(int difference)
{
// no-op
}
- /** No-op */
+ /**
+ * No-op
+ */
public void removeNodeEntry(NodeEntry entry)
{
// no-op
}
-
- static class NullQueueIterator implements Iterator
+
+ static class NullQueueIterator implements Iterator<NodeEntry>
{
private static final NullQueueIterator INSTANCE = new NullQueueIterator();
- private NullQueueIterator() {}
-
+ private NullQueueIterator()
+ {
+ }
+
public boolean hasNext()
{
return false;
}
- public Object next()
+ public NodeEntry next()
{
throw new NoSuchElementException("No more elements");
}
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/ResourceDMBean.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/ResourceDMBean.java 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/ResourceDMBean.java 2008-08-18 13:34:16
UTC (rev 6574)
@@ -27,16 +27,23 @@
import org.jboss.cache.jmx.annotations.ManagedAttribute;
import org.jboss.cache.jmx.annotations.ManagedOperation;
-import javax.management.*;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.DynamicMBean;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.ReflectionException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-import java.lang.reflect.Method;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
/**
* This class was entirely copied from jgroups (same name there).
@@ -49,13 +56,13 @@
public class ResourceDMBean implements DynamicMBean
{
private static final Class<?>[] primitives = {int.class,
- byte.class,
- short.class,
- long.class,
- float.class,
- double.class,
- boolean.class,
- char.class};
+ byte.class,
+ short.class,
+ long.class,
+ float.class,
+ double.class,
+ boolean.class,
+ char.class};
private static final String MBEAN_DESCRITION = "Dynamic MBean Description";
@@ -82,35 +89,43 @@
attrInfo = new MBeanAttributeInfo[atts.size()];
int i = 0;
- log.info("Processing class " + instance.getClass());
- log.info("Attributes are:");
- MBeanAttributeInfo info = null;
+ if (log.isInfoEnabled())
+ {
+ log.info("Processing class " + instance.getClass());
+ log.info("Number of attributes: " + atts.size());
+ }
+ MBeanAttributeInfo info;
for (AttributeEntry entry : atts.values())
{
info = entry.getInfo();
attrInfo[i++] = info;
- log.info("Attribute " + info.getName()
- + "[r="
- + info.isReadable()
- + ",w="
- + info.isWritable()
- + ",is="
- + info.isIs()
- + ",type="
- + info.getType()
- + "]");
+ if (log.isInfoEnabled())
+ {
+ log.info("Attribute " + info.getName()
+ + "[r="
+ + info.isReadable()
+ + ",w="
+ + info.isWritable()
+ + ",is="
+ + info.isIs()
+ + ",type="
+ + info.getType()
+ + "]");
+ }
}
opInfo = new MBeanOperationInfo[ops.size()];
ops.toArray(opInfo);
- if (ops.size() > 0)
- log.info("Operations are:");
- for (MBeanOperationInfo op : opInfo)
+ if (log.isInfoEnabled())
{
- log.info("Operation " + op.getReturnType() + " " +
op.getName());
+ if (ops.size() > 0)
+ log.info("Operations are:");
+ for (MBeanOperationInfo op : opInfo)
+ {
+ log.info("Operation " + op.getReturnType() + " " +
op.getName());
+ }
}
-
}
Object getObject()
Modified:
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/config/parsing/EvictionElementParserTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -34,13 +34,16 @@
{
String xml =
" <eviction wakeUpInterval=\"5\">\n" +
- " <default
algorithmClass=\"org.jboss.cache.eviction.MRUAlgorithm\"/>\n" +
+ " <default
algorithmClass=\"org.jboss.cache.eviction.MRUAlgorithm\">\n" +
+ " <attribute
name=\"maxNodes\">10</attribute>\n" +
+ " <attribute
name=\"minTimeToLive\">10</attribute>\n" +
+ " </default>\n" +
" <region name=\"/org/jboss/xyz\"
eventQueueSize=\"21\">\n" +
" <attribute
name=\"maxNodes\">2103</attribute>\n" +
" <attribute
name=\"minTimeToLive\">22</attribute>\n" +
" </region>\n" +
" </eviction>";
- EvictionConfig evictionConfig = getEvictionConfig(xml);
+ EvictionConfig evictionConfig = getEvictionConfig(xml, false);
assert evictionConfig.getDefaultEvictionRegionConfig().getEventQueueSize() ==
EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
assert
evictionConfig.getDefaultEvictionRegionConfig().getEvictionActionPolicyClassName().equals(DefaultEvictionActionPolicy.class.getName());
}
@@ -59,7 +62,7 @@
" </eviction>";
try
{
- EvictionConfig config = getEvictionConfig(xml);
+ EvictionConfig config = getEvictionConfig(xml, false);
assert false : "Should throw ConfigurationException!";
}
catch (ConfigurationException good)
@@ -89,7 +92,7 @@
" <attribute
name=\"timeToLive\">22</attribute>\n" +
" </region>\n" +
" </eviction>";
- EvictionConfig config = getEvictionConfig(xml);
+ EvictionConfig config = getEvictionConfig(xml, false);
//tests the defaults
assert config.getWakeupInterval() == 5;
assert config.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig()
instanceof MRUAlgorithmConfig;
@@ -144,7 +147,7 @@
" <attribute
name=\"timeToLive\">1000000</attribute>\n" +
" </region>\n" +
" </eviction>";
- EvictionConfig evConfig = getEvictionConfig(xml);
+ EvictionConfig evConfig = getEvictionConfig(xml, false);
EvictionRegionConfig evictionRegionConfig =
evConfig.getDefaultEvictionRegionConfig();
assert evictionRegionConfig.getRegionName().equals(Fqn.ROOT.toString()) : "Was
" + evictionRegionConfig.getRegionName();
assert ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive() == 1000000;
@@ -169,7 +172,7 @@
" </eviction>";
try
{
- getEvictionConfig(xml);
+ getEvictionConfig(xml, false);
assert false : "exception expected as wake up interval is not set";
}
catch (ConfigurationException e)
@@ -192,7 +195,7 @@
" </eviction>";
try
{
- getEvictionConfig(xml);
+ getEvictionConfig(xml, false);
assert false : "missing policy in both default and region, exception
expected.";
}
catch (MissingPolicyException e)
@@ -212,12 +215,12 @@
" <attribute
name=\"timeToLive\">1002</attribute>\n" +
" </region>\n" +
" </eviction>";
- EvictionConfig ec = getEvictionConfig(xml);
+ EvictionConfig ec = getEvictionConfig(xml, false);
assert ec.getEvictionRegionConfigs().get(0).getEventQueueSize() ==
EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
}
- private EvictionConfig getEvictionConfig(String xml)
+ private EvictionConfig getEvictionConfig(String xml, boolean validate)
{
Element el;
try
@@ -228,7 +231,13 @@
{
throw new ConfigurationException(e);
}
- return parser.parseEvictionElement(el);
+ EvictionConfig cfg = parser.parseEvictionElement(el);
+ if (validate)
+ {
+ cfg.getDefaultEvictionRegionConfig().validate();
+ for (EvictionRegionConfig erc : cfg.getEvictionRegionConfigs()) erc.validate();
+ }
+ return cfg;
}
public void testMissingDefaultEvictionClass() throws Exception
@@ -246,7 +255,7 @@
" </eviction>";
try
{
- getEvictionConfig(xml);
+ getEvictionConfig(xml, true);
assert false : " exception expected as default element does not have a
eviction policy defined";
}
catch (MissingPolicyException e)
@@ -268,7 +277,7 @@
" <region name=\"/two\"
actionPolicyClass=\"" + DefaultEvictionActionPolicy.class.getName() +
"\">\n" +
" </region>\n" +
" </eviction>";
- EvictionConfig config = getEvictionConfig(xml);
+ EvictionConfig config = getEvictionConfig(xml, false);
// default region
assert config.getDefaultEvictionRegionConfig().getEvictionAlgorithmConfig()
instanceof NullEvictionAlgorithmConfig;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ConcurrentEvictionTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -90,7 +90,7 @@
Fqn.ROOT,
new LRUAlgorithmConfig(1000000, 5000)
),
- 5000);
+ 200);
}
@AfterMethod(alwaysRun = true)
@@ -119,9 +119,8 @@
for (int i = 0; i < 1000; i++)
{
Fqn fqn = Fqn.fromRelativeElements(base, i / 100);
- Integer key = i;
- assertNotNull("found value under Fqn " + fqn + " and key
" + key,
- cache.get(fqn, key));
+ assertNotNull("found value under Fqn " + fqn + " and key
" + i,
+ cache.get(fqn, i));
}
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeAlgorithmTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -1,24 +1,19 @@
package org.jboss.cache.eviction;
import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
-import org.jboss.cache.RegionRegistry;
-import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.Iterator;
-
/**
* @author Daniel Huang
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class ElementSizeAlgorithmTest
+public class ElementSizeAlgorithmTest extends EvictionTestsBase
{
RegionManager regionManager;
ElementSizeAlgorithm algo;
@@ -26,15 +21,10 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- algo = new ElementSizeAlgorithm();
regionManager = new RegionManagerImpl();
- ((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
ElementSizeAlgorithmConfig config = new ElementSizeAlgorithmConfig();
- // We have to setCache maxElementsPerNode!!
config.setMaxElementsPerNode(0);
-// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- Region r = regionManager.getRegion("/a/b", true);
- r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
+ algo = (ElementSizeAlgorithm) createAndAssignToRegion("/a/b",
regionManager, config);
}
public void testMaxElements() throws Exception
@@ -63,11 +53,9 @@
assertEquals(9, algo.getEvictionQueue().getNumberOfNodes());
assertEquals(12, algo.getEvictionQueue().getNumberOfElements());
// now verify the order.
- Iterator it = queue.iterate();
int count = 6;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
System.out.println(ne);
if (count > 0)
@@ -117,11 +105,9 @@
assertEquals(45, algo.getEvictionQueue().getNumberOfElements());
// now verify the order.
- Iterator it = queue.iterate();
int num = 9;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
assertEquals(num, ne.getNumberOfElements());
num--;
}
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeConfigurationTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -29,7 +29,8 @@
"</region>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(100, config.getMaxElementsPerNode());
assertEquals(1000, config.getMaxNodes());
@@ -46,7 +47,8 @@
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
}
catch (ConfigurationException ce)
{
@@ -67,7 +69,8 @@
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(100, config.getMaxElementsPerNode());
assertEquals(0, config.getMaxNodes());
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -17,17 +17,23 @@
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionWatcher;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
/**
* @author Daniel Huang
* @version $Revison: $
*/
@Test(groups = {"functional"})
-public class ElementSizePolicyTest
+public class ElementSizePolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache;
long wakeupIntervalMillis = 0;
@@ -41,7 +47,6 @@
{
initCaches();
wakeupIntervalMillis =
cache.getConfiguration().getEvictionConfig().getWakeupInterval();
- log("wakeupInterval is " + wakeupIntervalMillis);
if (wakeupIntervalMillis < 0)
{
fail("testEviction(): eviction thread wake up interval is illegal " +
wakeupIntervalMillis);
@@ -54,8 +59,7 @@
void initCaches() throws Exception
{
Configuration conf =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
ElementSizeAlgorithmConfig(5000, 100)), 3000);
- evConfig.setDefaultEventQueueSize(200000);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
ElementSizeAlgorithmConfig(5000, 100), 200000), 200);
evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new
ElementSizeAlgorithmConfig(10, 20)));
evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
ElementSizeAlgorithmConfig(-1, 5)));
evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/test/"), new
ElementSizeAlgorithmConfig(5000, 1)));
@@ -98,13 +102,15 @@
}
System.out.println(cache);
- _sleep(wakeupIntervalMillis + 500);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS,
Fqn.fromString("/org/jboss/test/data/8")) : "Eviction event not
received!";
+ TestingUtil.sleepThread(200); // small grace period
System.out.println(cache);
for (int i = 0; i < 10; i++)
{
- Node node = cache.getNode("/org/jboss/test/data/" +
Integer.toString(i));
- System.out.println(node);
+ String f = "/org/jboss/test/data/" + i;
+ Node node = cache.getNode(f);
+ System.out.println("Node for " + f + " is " + node);
if (i % 2 == 0)
{
if (i < 6)
@@ -126,6 +132,10 @@
public void testEviction2() throws Exception
{
+ List<Fqn> fqnsThatShouldBeEvicted = new ArrayList<Fqn>();
+ for (int i = 10; i < 20; i++)
fqnsThatShouldBeEvicted.add(Fqn.fromString("/org/jboss/data/" + i));
+
+ EvictionWatcher watcher = new EvictionWatcher(cache, fqnsThatShouldBeEvicted);
String rootStr = "/org/jboss/data/";
for (int i = 0; i < 20; i++)
{
@@ -138,7 +148,7 @@
}
}
- _sleep(wakeupIntervalMillis + 500);
+ assert watcher.waitForEviction(30, TimeUnit.SECONDS) : "Eviction events never
received!";
for (int i = 0; i < 20; i++)
{
@@ -158,14 +168,16 @@
for (int i = 0; i < 17; i++)
{
- cache.put("/org/jboss/data/" + Integer.toString(3), 100 + i,
"value");
+ cache.put("/org/jboss/data/3", 100 + i, "value");
}
- Node node = cache.getNode("/org/jboss/data/" + Integer.toString(3));
+ Node node = cache.getNode("/org/jboss/data/3");
assertEquals(21, node.getData().size());
- _sleep(wakeupIntervalMillis + 500);
- assertNull(cache.getNode("/org/jboss/data/" + Integer.toString(3)));
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS,
Fqn.fromString("/org/jboss/data/3")) : "Eviction event not
received!";
+ TestingUtil.sleepThread(200); // small grace period
+
+ assertNull(cache.getNode("/org/jboss/data/3"));
}
class MyPutter extends Thread
@@ -184,7 +196,6 @@
try
{
cache.put(myName + i++, "value", i);
- sleep(1);
}
catch (Throwable e)
{
@@ -197,54 +208,4 @@
}
}
}
-
-
- public void testConcurrentPutAndEvict() throws Exception
- {
- cache.stop();
- cache.destroy();
- cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
-
- cache.start();
- cache.put(ROOT_STR + "/concurrentPutAndEvict", "value", 1);
-
- for (int i = 0; i < 10; i++)
- {
- new MyPutter("Putter" + i).start();
- }
-
- int counter = 0;
- while (true)
- {
- counter++;
- if (t1_ex != null)
- {
- fail("Exception generated in put() " + t1_ex);
- }
- log("nodes/locks: " + cache.getNumberOfNodes() + "/" +
cache.getNumberOfLocksHeld());
- _sleep(1000);
- if (counter > 10)
- {// run for 10 seconds
- isTrue = false;
- break;
- }
- }
- }
-
- private void _sleep(long msecs)
- {
- try
- {
- Thread.sleep(msecs);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();//To change body of catch statement use File | Settings |
File Templates.
- }
- }
-
- private void log(String msg)
- {
- System.out.println("-- " + msg);
- }
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeQueueTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeQueueTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizeQueueTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -6,20 +6,14 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
/**
* @author Daniel Huang
* @version $Revision$
@@ -38,11 +32,9 @@
public void testQueue() throws Exception
{
- NodeEntry ne;
for (int i = 0; i < 500; i++)
{
- ne = new NodeEntry("/a/b/c/" + Integer.toString(i));
- queue.addNodeEntry(ne);
+ queue.addNodeEntry(new NodeEntry("/a/b/c/" + Integer.toString(i)));
}
queue.resortEvictionQueue();
@@ -54,11 +46,9 @@
assertEquals("/a/b/c/275", ne275.getFqn().toString());
// now make sure the ordering is correct.
- Iterator it = queue.iterate();
int k = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- ne = (NodeEntry) it.next();
assertEquals("/a/b/c/" + Integer.toString(k),
ne.getFqn().toString());
if (k % 2 == 0)
{
@@ -70,20 +60,19 @@
queue.resortEvictionQueue();
k = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- ne = (NodeEntry) it.next();
System.out.println(ne.toString());
+
+ // the first 250 elements should have (250 - 1 - n) * 2 elements. The rest
should have 0 elements.
+ int expectedElements = 0;
if (k < 250)
{
- assertEquals(k, ne.getNumberOfElements());
- assertEquals(0, k % 2);
+ expectedElements = (250 - 1 - k) * 2;
}
- else
- {
- assertTrue(k % 2 != 0);
- assertEquals(0, ne.getNumberOfElements());
- }
+
+ assertEquals("k is " + k, expectedElements,
ne.getNumberOfElements());
+
k++;
}
}
@@ -95,12 +84,9 @@
queue.addNodeEntry(new NodeEntry("/a/b/c/" + Integer.toString(i)));
}
- NodeEntry ne;
- Iterator it = queue.iterate();
int i = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- ne = (NodeEntry) it.next();
if (i % 2 == 0)
{
queue.removeNodeEntry(ne);
@@ -110,15 +96,13 @@
assertEquals(2500, queue.getNumberOfNodes());
- Set removalQueue = queue.getRemovalQueue();
- List evictionList = queue.getEvictionList();
+ Set<NodeEntry> removalQueue = queue.getRemovalQueue();
+ List<NodeEntry> evictionList = queue.getEvictionList();
assertEquals(2500, removalQueue.size());
- it = removalQueue.iterator();
- while (it.hasNext())
+ for (NodeEntry ne : removalQueue)
{
- ne = (NodeEntry) it.next();
int currentIndex = Integer.parseInt((String) ne.getFqn().get(3));
assertEquals(0, currentIndex % 2);
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -71,7 +71,7 @@
assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
assertEquals(5000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
assertEquals(1000000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
- assertEquals(0, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
+ assertEquals(-1, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
}
finally
@@ -110,7 +110,7 @@
assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
assertEquals(5000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
assertEquals(1000000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
- assertEquals(0, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
+ assertEquals(-1, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
region = regionManager.getRegion("/maxAgeTest", false);
evictionRegionConfig = region.getEvictionRegionConfig();
@@ -174,7 +174,7 @@
assertTrue(evictionRegionConfig.getEvictionAlgorithmConfig() instanceof
LRUAlgorithmConfig);
assertEquals(5000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxNodes());
assertEquals(1000000, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getTimeToLive());
- assertEquals(0, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
+ assertEquals(-1, ((LRUAlgorithmConfig)
evictionRegionConfig.getEvictionAlgorithmConfig()).getMaxAge());
}
finally
Added: core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java
(rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/EvictionTestsBase.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -0,0 +1,53 @@
+package org.jboss.cache.eviction;
+
+import org.easymock.EasyMock;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionManagerImpl;
+import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionAlgorithmConfig;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionWatcher;
+
+import java.util.concurrent.TimeUnit;
+
+public abstract class EvictionTestsBase
+{
+ public EvictionAlgorithm createAndAssignToRegion(String fqnString, RegionManager
regionManager, EvictionAlgorithmConfig config)
+ {
+ Fqn fqn = Fqn.fromString(fqnString);
+ Configuration c = new Configuration();
+ c.setEvictionConfig(new EvictionConfig());
+ EvictionRegionConfig erc = new EvictionRegionConfig(fqn, config);
+ c.getEvictionConfig().addEvictionRegionConfig(erc);
+ CacheSPI mockCache = EasyMock.createNiceMock(CacheSPI.class);
+ EasyMock.replay(mockCache);
+ ((RegionManagerImpl) regionManager).injectDependencies(mockCache, c, null, null,
null, new RegionRegistry());
+ Region r = regionManager.getRegion(fqn, Region.Type.EVICTION, true);
+ r.setEvictionRegionConfig(erc);
+
+ ((RegionManagerImpl) regionManager).start();
+ return (EvictionAlgorithm) TestingUtil.extractField(r,
"evictionAlgorithm");
+ }
+
+ /**
+ * Blocks until an eviction event is seen on the given cache for the given array of
Fqns. Returns true if the eviction event
+ * is received, false if it times out.
+ *
+ * @param cache cache to monitor
+ * @param timeToWait timeout
+ * @param unit timeout unit
+ * @param fqnsToEvict fqns to watch for
+ * @return true if evicted, false otherwise
+ */
+ public boolean waitForEviction(Cache cache, long timeToWait, TimeUnit unit, Fqn...
fqnsToEvict) throws InterruptedException
+ {
+ return new EvictionWatcher(cache, fqnsToEvict).waitForEviction(timeToWait, unit);
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -21,6 +21,8 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.TimeUnit;
+
/**
* Unit tests for {@link org.jboss.cache.eviction.ExpirationAlgorithm}.
*
@@ -28,7 +30,7 @@
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class ExpirationPolicyTest
+public class ExpirationPolicyTest extends EvictionTestsBase
{
private static final Log log = LogFactory.getLog(ExpirationPolicyTest.class);
@@ -49,13 +51,13 @@
ExpirationAlgorithmConfig eAC = new ExpirationAlgorithmConfig();
EvictionRegionConfig eRC = new EvictionRegionConfig(Fqn.ROOT, eAC);
EvictionConfig econf = new EvictionConfig(eRC);
- econf.setWakeupInterval(1000);
+ econf.setWakeupInterval(100);
conf.setEvictionConfig(econf);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(conf, false);
cache.start();
- future = System.currentTimeMillis() + 4000;
- past = System.currentTimeMillis() - 2000;
+ future = System.currentTimeMillis() + 500;
+ past = System.currentTimeMillis() - 200;
}
@AfterMethod(alwaysRun = true)
@@ -70,14 +72,14 @@
cache.put(fqn2, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
cache.put(fqn3, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
cache.put(fqn4, "foo", "bar");
- TestingUtil.sleepThread(2000);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, fqn2) : "Eviction event
not received!";
assertNotNull(cache.getNode(fqn1));
assertNull(cache.getNode(fqn2));
assertNotNull(cache.getNode(fqn3));
assertNotNull(cache.getNode(fqn4));
log.info("should remove 1 and 3 now");
- TestingUtil.sleepThread(3000);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, fqn1, fqn3) : "Eviction
event not received!";
assertNull(cache.getNode(fqn1));
assertNull(cache.getNode(fqn3));
}
@@ -87,25 +89,23 @@
log.info("update 1 from future to past");
cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
assertNotNull(cache.getNode(fqn1));
- TestingUtil.sleepThread(1500);
cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
- TestingUtil.sleepThread(1500);
+ assert waitForEviction(cache, 1, TimeUnit.SECONDS, fqn1) : "Eviction event not
received!";
assertNull(cache.getNode(fqn1));
cache.removeNode(Fqn.ROOT);
-
}
public void testUpdateToFuture() throws Exception
{
log.info("update 1 from future to past");
- Long future2 = future + 2000;
+ Long future2 = future + 200;
cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
- TestingUtil.sleepThread(2000);
+ TestingUtil.sleepThread(200);
assertNotNull(cache.getNode(fqn1));
cache.put(fqn1, ExpirationAlgorithmConfig.EXPIRATION_KEY, future2);
- TestingUtil.sleepThread(3000);
+ TestingUtil.sleepThread(500);
assertNotNull(cache.getNode(fqn1));
- TestingUtil.sleepThread(3000);
+ TestingUtil.sleepThread(100);
assertNull(cache.getNode(fqn1));
cache.removeNode(Fqn.ROOT);
}
@@ -122,7 +122,7 @@
cache.put(fqn3, ExpirationAlgorithmConfig.EXPIRATION_KEY, future);
cache.put(fqn4, ExpirationAlgorithmConfig.EXPIRATION_KEY, past);
assertEquals(5, cache.getNumberOfNodes());
- Thread.sleep(2000);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, fqn3) : "Eviction event
not received!";
assertNotNull(cache.getNode(fqn1));
assertNotNull(cache.getNode(fqn2));
assertNull(cache.getNode(fqn3));
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOAlgorithmTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -7,19 +7,15 @@
package org.jboss.cache.eviction;
import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
import org.jboss.cache.RegionRegistry;
-import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.Iterator;
-
/**
* Unit tests for FIFOAlgorithm.
*
@@ -27,7 +23,7 @@
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class FIFOAlgorithmTest
+public class FIFOAlgorithmTest extends EvictionTestsBase
{
RegionManager regionManager;
@@ -36,15 +32,11 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- algo = new FIFOAlgorithm();
- FIFOAlgorithmConfig config = new FIFOAlgorithmConfig();
- // We have to setCache maxNodes!!
- config.setMaxNodes(0);
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
-// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- Region r = regionManager.getRegion("/a/b", true);
- r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
+ FIFOAlgorithmConfig config = new FIFOAlgorithmConfig();
+ config.setMaxNodes(0);
+ algo = (FIFOAlgorithm) createAndAssignToRegion("/a/b", regionManager,
config);
}
public void testMaxNodes1() throws Exception
@@ -64,11 +56,9 @@
assertEquals(5, algo.getEvictionQueue().getNumberOfNodes());
// now verify the order.
- Iterator it = queue.iterate();
int index = 3;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
String fqn = ne.getFqn().toString();
assertTrue(fqn.endsWith("/" + Integer.toString(index)));
index++;
@@ -90,11 +80,9 @@
assertEquals(5, algo.getEvictionQueue().getNumberOfNodes());
- it = queue.iterate();
index = 3;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
String fqn = ne.getFqn().toString();
assertTrue(fqn.endsWith("/" + Integer.toString(index)));
index++;
@@ -105,9 +93,9 @@
{
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
FIFOAlgorithmConfig config = (FIFOAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
- config.setMaxNodes(50000);
+ config.setMaxNodes(500);
- for (int i = 0; i < 50000; i++)
+ for (int i = 0; i < 500; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -115,18 +103,16 @@
algo.process(region.getEvictionEventQueue());
FIFOQueue queue = (FIFOQueue) algo.evictionQueue;
- assertEquals(50000, algo.getEvictionQueue().getNumberOfNodes());
+ assertEquals(500, algo.getEvictionQueue().getNumberOfNodes());
- Iterator it = queue.iterate();
int index = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
assertTrue(ne.getFqn().toString().endsWith("/" +
Integer.toString(index)));
index++;
}
- for (int i = 50000; i < 60000; i++)
+ for (int i = 500; i < 600; i++)
{
Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -134,11 +120,9 @@
algo.process(region.getEvictionEventQueue());
- it = queue.iterate();
- index = 10000;
- while (it.hasNext())
+ index = 100;
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
assertTrue(ne.getFqn().toString().endsWith("/" +
Integer.toString(index)));
index++;
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOConfigurationTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -31,7 +31,8 @@
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(1000, config.getMaxNodes());
@@ -47,7 +48,8 @@
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
}
catch (ConfigurationException ce)
{
@@ -68,7 +70,8 @@
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
}
catch (ConfigurationException ce)
{
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -17,11 +17,16 @@
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.util.internals.EvictionController;
+import org.jboss.cache.util.internals.EvictionWatcher;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
/**
* Unit tests for FIFOPolicy.
*
@@ -29,14 +34,14 @@
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class FIFOPolicyTest
+public class FIFOPolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache;
long wakeupIntervalMillis = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
- final long DURATION = 10000;
- boolean isTrue;
+ volatile boolean isTrue;
+ int maxNodes = 50;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -56,8 +61,7 @@
void initCaches() throws Exception
{
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
FIFOAlgorithmConfig(5000)), 3000);
- evConfig.setDefaultEventQueueSize(20000);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
FIFOAlgorithmConfig(maxNodes), 2000000), 200);
evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
FIFOAlgorithmConfig(5)));
config.setEvictionConfig(evConfig);
config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
@@ -112,7 +116,6 @@
public void testEviction2() throws Exception
{
String rootStr = "/org/jboss/data";
- int maxNodes = 5000;
for (int i = 0; i < maxNodes * 2; i++)
{
String str = rootStr + i;
@@ -122,6 +125,8 @@
EvictionController evictionController = new EvictionController(cache);
evictionController.startEviction();
+ // wait a few secs for eviction to complete
+ TestingUtil.sleepThread(500);
assertEquals("Number of nodes", maxNodes + 2, cache.getNumberOfNodes());
for (int i = 0; i < maxNodes; i++)
{
@@ -145,9 +150,13 @@
assertNotNull(cache.get(rootStr + "a", rootStr + "a"));
}
- public void testNodeVisited()
+ public void testNodeVisited() throws InterruptedException
{
String rootStr = "/org/jboss/test/data/";
+ List<Fqn> fqnsToBeEvicted = new ArrayList<Fqn>();
+ for (int i = 0; i < 5; i++) fqnsToBeEvicted.add(Fqn.fromString(rootStr + i));
+ EvictionWatcher watcher = new EvictionWatcher(cache, fqnsToBeEvicted);
+
for (int i = 0; i < 10; i++)
{
String str = rootStr + i;
@@ -163,9 +172,8 @@
}
}
- long period = wakeupIntervalMillis + 500;
+ assert watcher.waitForEviction(30, TimeUnit.SECONDS) : "Eviction event not
received!";
- log("sleeping for " + period + "ms");
EvictionController evictionController = new EvictionController(cache);
evictionController.startEviction();
try
@@ -183,14 +191,12 @@
assertNotNull(cache.get(fqn, str));
}
- evictionController.startEviction();
// since it is FIFO if we leave it alone and revisit, cache should remain the
same.
for (int i = 5; i < 10; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
cache.get(fqn, str);// just to keep it fresh
- System.out.println("-- sleeping for " + period + "ms");
}
}
catch (Exception e)
@@ -282,7 +288,7 @@
try
{
cache.put(myName + i++, "value", i);
- sleep(1);
+ TestingUtil.sleepThread(2);
}
catch (Throwable e)
{
@@ -304,10 +310,12 @@
cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
cache.start();
cache.put(ROOT_STR + "/concurrentPutAndEvict", "value", 1);
-
+ List<MyPutter> putters = new ArrayList<MyPutter>();
for (int i = 0; i < 10; i++)
{
- new MyPutter("Putter" + i).start();
+ MyPutter p = new MyPutter("Putter" + i);
+ putters.add(p);
+ p.start();
}
int counter = 0;
@@ -320,12 +328,14 @@
}
log("nodes/locks: " + cache.getNumberOfNodes() + "/" +
cache.getNumberOfLocksHeld());
TestingUtil.sleepThread(1000);
- if (counter > 10)
- {// run for 10 seconds
+ if (counter > 5)
+ {// run for 5 seconds
isTrue = false;
break;
}
}
+
+ for (MyPutter p : putters) p.join();
}
void log(String msg)
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -10,15 +10,12 @@
import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
-import org.jboss.cache.RegionRegistry;
import org.jboss.cache.config.EvictionRegionConfig;
import static org.jboss.cache.eviction.EvictionEvent.Type.*;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.Iterator;
-
/**
* Unit test for LFUAlgorithm.
*
@@ -26,20 +23,18 @@
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class LFUAlgorithmTest
+public class LFUAlgorithmTest extends EvictionTestsBase
{
RegionManager regionManager;
LFUAlgorithm algo;
+ LFUAlgorithmConfig config;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- algo = new LFUAlgorithm();
- LFUAlgorithmConfig config = new LFUAlgorithmConfig();
regionManager = new RegionManagerImpl();
- ((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- regionManager.getRegion("/a/b", true).setEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/a/b"), config));
- // doesn't this need a cache?!?? :-/
+ config = new LFUAlgorithmConfig();
+ algo = (LFUAlgorithm) createAndAssignToRegion("/a/b", regionManager,
config);
}
public void testMaxNode1()
@@ -47,10 +42,8 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LFUAlgorithmConfig config = new LFUAlgorithmConfig();
- config.setMaxNodes(0);
+ config.setMaxNodes(-1);
config.setMinNodes(20);
- region.setEvictionRegionConfig(new EvictionRegionConfig(region.getFqn(), config));
region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
try
@@ -72,10 +65,8 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LFUAlgorithmConfig config = new LFUAlgorithmConfig();
config.setMaxNodes(1);
config.setMinNodes(20);
- region.setEvictionRegionConfig(new EvictionRegionConfig(region.getFqn(), config));
region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
@@ -116,7 +107,7 @@
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
LFUAlgorithmConfig config = (LFUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
- config.setMaxNodes(0);
+ config.setMaxNodes(-1);
config.setMinNodes(2);
region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
@@ -137,8 +128,8 @@
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
LFUAlgorithmConfig config = (LFUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
- config.setMaxNodes(0);
- config.setMinNodes(0);
+ config.setMaxNodes(-1);
+ config.setMinNodes(-1);
region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
@@ -164,7 +155,7 @@
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
LFUAlgorithmConfig config = (LFUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
- config.setMaxNodes(0);
+ config.setMaxNodes(-1);
config.setMinNodes(100);
region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
@@ -181,11 +172,9 @@
algo.process(region.getEvictionEventQueue());
LFUQueue queue = (LFUQueue) algo.evictionQueue;
assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());
- Iterator it = queue.iterate();
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " +
ne.getNumberOfNodeVisits());
assertEquals(1, ne.getNumberOfNodeVisits());
}
@@ -219,12 +208,10 @@
System.out.println();
System.out.println();
- it = queue.iterate();
int count = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
count++;
- NodeEntry ne = (NodeEntry) it.next();
System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " +
ne.getNumberOfNodeVisits());
if (count == 5 || count == 6)
{
@@ -261,12 +248,10 @@
System.out.println();
System.out.println();
- it = queue.iterate();
count = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
count++;
- NodeEntry ne = (NodeEntry) it.next();
System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " +
ne.getNumberOfNodeVisits());
if (count == 7 || count == 8)
{
@@ -301,12 +286,10 @@
System.out.println();
System.out.println();
- it = queue.iterate();
count = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
count++;
- NodeEntry ne = (NodeEntry) it.next();
System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " +
ne.getNumberOfNodeVisits());
if (count == 5 || count == 6)
{
@@ -348,12 +331,10 @@
System.out.println();
System.out.println();
- it = queue.iterate();
count = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
count++;
- NodeEntry ne = (NodeEntry) it.next();
System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " +
ne.getNumberOfNodeVisits());
if (count == 5 || count == 6)
{
@@ -380,7 +361,7 @@
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
EvictionRegionConfig config = region.getEvictionRegionConfig();
- ((LFUAlgorithmConfig) config.getEvictionAlgorithmConfig()).setMaxNodes(0);
+ ((LFUAlgorithmConfig) config.getEvictionAlgorithmConfig()).setMaxNodes(-1);
((LFUAlgorithmConfig) config.getEvictionAlgorithmConfig()).setMinNodes(10000);
for (int i = 0; i < 10000; i++)
{
@@ -390,12 +371,10 @@
algo.process(region.getEvictionEventQueue());
LFUQueue queue = (LFUQueue) algo.evictionQueue;
- Iterator it = queue.iterate();
long lastModifiedTimestamp = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
assertTrue(lastModifiedTimestamp <= ne.getModifiedTimeStamp());
lastModifiedTimestamp = ne.getModifiedTimeStamp();
}
@@ -411,12 +390,10 @@
algo.process(region.getEvictionEventQueue());
- it = queue.iterate();
int count = 0;
lastModifiedTimestamp = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- NodeEntry ne = (NodeEntry) it.next();
assertTrue(lastModifiedTimestamp <= ne.getModifiedTimeStamp());
lastModifiedTimestamp = ne.getModifiedTimeStamp();
@@ -434,5 +411,4 @@
assertEquals(10000, algo.getEvictionQueue().getNumberOfNodes());
}
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUConfigurationTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -33,7 +33,8 @@
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(10, config.getMinNodes());
assertEquals(20, config.getMaxNodes());
@@ -48,7 +49,8 @@
"</region>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(10, config.getMinNodes());
assertEquals(0, config.getMaxNodes());
@@ -63,9 +65,10 @@
"</region>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
- assertEquals(0, config.getMinNodes());
+ assertEquals(-1, config.getMinNodes());
assertEquals(20, config.getMaxNodes());
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -15,11 +15,16 @@
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionWatcher;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
/**
* Unit tests for LFU Policy.
*
@@ -27,14 +32,14 @@
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class LFUPolicyTest
+public class LFUPolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache;
long wakeupIntervalMillis = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
- final long DURATION = 10000;
boolean isTrue;
+ int maxNodesDefault = 500, minNodesDefault = 10, maxNodesR1 = 200, minNodesR1 = 100,
maxNodesR2 = -1, minNodesR2 = 5;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -54,10 +59,9 @@
void initCaches() throws Exception
{
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LFUAlgorithmConfig(500, 10)), 3000);
- evConfig.setDefaultEventQueueSize(200000);
- evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new
LFUAlgorithmConfig(5000, 4000)));
- evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
LFUAlgorithmConfig(-1, 5)));
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LFUAlgorithmConfig(maxNodesDefault, minNodesDefault), 200000), 200);
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/data"), new
LFUAlgorithmConfig(maxNodesR1, minNodesR1)));
+ evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
LFUAlgorithmConfig(maxNodesR2, minNodesR2)));
config.setEvictionConfig(evConfig);
config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
config.setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -72,8 +76,13 @@
public void testEviction() throws Exception
{
+ int numNodes = (int) ((maxNodesR1 * 2.6) - 1);
String rootStr = "/org/jboss/data/";
- for (int i = 0; i < 8000; i++)
+ List<Fqn> fqns = new ArrayList<Fqn>();
+ for (int i = 0; i < numNodes; i += 2) fqns.add(Fqn.fromString(rootStr + i));
+ EvictionWatcher ew = new EvictionWatcher(cache, fqns);
+ List<Fqn> toRevisit = new ArrayList<Fqn>();
+ for (int i = 0; i < numNodes; i++)
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
@@ -88,16 +97,13 @@
}
// visit odd numbered nodes an extra time to make them get evicted last.
- if (i % 2 != 0)
- {
- cache.get(fqn, str);
- }
+ if (i % 2 != 0) toRevisit.add(fqn);
+ revisit(toRevisit);
}
- long period = wakeupIntervalMillis + 500;
- TestingUtil.sleepThread(period);
+ assert ew.waitForEviction(30, TimeUnit.SECONDS);
- for (int i = 0; i < 8000; i++)
+ for (int i = 0; i < numNodes; i++)
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
@@ -113,9 +119,17 @@
}
}
- public void testNodeVisited()
+ private void revisit(List<Fqn> fqns)
{
+ for (Fqn fqn : fqns) cache.getNode(fqn);
+ }
+
+ public void testNodeVisited() throws InterruptedException
+ {
String rootStr = "/org/jboss/test/data/";
+ List<Fqn> fqns = new ArrayList<Fqn>();
+ for (int i = 0; i < 5; i++) fqns.add(Fqn.fromString(rootStr + i));
+ EvictionWatcher ew = new EvictionWatcher(cache, fqns);
for (int i = 0; i < 10; i++)
{
String str = rootStr + i;
@@ -131,11 +145,8 @@
}
}
- long period = wakeupIntervalMillis + 500;
+ assert ew.waitForEviction(30, TimeUnit.SECONDS);
- log("sleeping for " + period + "ms");
- TestingUtil.sleepThread(period);// it really depends the eviction thread time.
-
try
{
for (int i = 0; i < 5; i++)
@@ -151,8 +162,6 @@
assertNotNull(cache.get(fqn, str));
}
- TestingUtil.sleepThread(period);
-
// since min is 5 the cache won't deplete past 5 nodes left in the cache.
for (int i = 5; i < 10; i++)
{
@@ -184,7 +193,11 @@
}
}
- TestingUtil.sleepThread(period);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS,
+ Fqn.fromString(rootStr + 7),
+ Fqn.fromString(rootStr + 8),
+ Fqn.fromString(rootStr + 9)
+ );
// now make sure we still only have 5 nodes and they are the ones we expect
based on LFU
for (int i = 5; i < 7; i++)
@@ -219,7 +232,7 @@
public void testNodeRemoved() throws Exception
{
String rootStr = "/org/jboss/data/";
- for (int i = 0; i < 5000; i++)
+ for (int i = 0; i < maxNodesR1; i++)
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
@@ -238,21 +251,21 @@
log("period is " + period);
TestingUtil.sleepThread(period);
- for (int i = 0; i < 1000; i++)
+ for (int i = 0; i < (maxNodesR1 - minNodesR1); i++)
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
assertNull(cache.get(fqn, str));
}
- for (int i = 1000; i < 5000; i++)
+ for (int i = (maxNodesR1 - minNodesR1); i < maxNodesR1; i++)
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
assertNotNull(cache.get(fqn, str));
}
- for (int i = 1000; i < 5000; i++)
+ for (int i = (maxNodesR1 - minNodesR1); i < maxNodesR1; i++)
{
if (i % 2 == 0)
{
@@ -265,7 +278,7 @@
TestingUtil.sleepThread(period);
- for (int i = 1000; i < 5000; i++)
+ for (int i = (maxNodesR1 - minNodesR1); i < maxNodesR1; i++)
{
if (i % 2 == 0)
{
@@ -332,8 +345,8 @@
}
log("nodes/locks: " + cache.getNumberOfNodes() + "/" +
cache.getNumberOfLocksHeld());
TestingUtil.sleepThread(1000);
- if (counter > 10)
- {// run for 10 seconds
+ if (counter > 5)
+ {// run for 5 seconds
isTrue = false;
break;
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUQueueTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUQueueTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUQueueTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -6,19 +6,13 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
/**
* Unit tests for LFUQueue.
*
@@ -53,16 +47,13 @@
NodeEntry ne275 = queue.getNodeEntry("/a/b/c/275");
assertEquals("/a/b/c/275", ne275.getFqn().toString());
- // now make sure the ordering is correct.
- Iterator it = queue.iterate();
int k = 0;
- while (it.hasNext())
+ for (NodeEntry entry : queue)
{
- ne = (NodeEntry) it.next();
- assertEquals("/a/b/c/" + Integer.toString(k),
ne.getFqn().toString());
+ assertEquals("/a/b/c/" + Integer.toString(k),
entry.getFqn().toString());
if (k % 2 == 0)
{
- ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
+ entry.setNumberOfNodeVisits(entry.getNumberOfNodeVisits() + 1);
}
k++;
}
@@ -72,18 +63,16 @@
assertEquals("/a/b/c/1", queue.getFirstNodeEntry().getFqn().toString());
// now check the sort order.
- it = queue.iterate();
k = 0;
- while (it.hasNext())
+ for (NodeEntry entry : queue)
{
- ne = (NodeEntry) it.next();
if (k < 250)
{
- assertEquals(0, ne.getNumberOfNodeVisits());
+ assertEquals(0, entry.getNumberOfNodeVisits());
}
else
{
- assertEquals(1, ne.getNumberOfNodeVisits());
+ assertEquals(1, entry.getNumberOfNodeVisits());
}
k++;
}
@@ -121,17 +110,15 @@
assertEquals(250, queue.getNumberOfNodes());
k = 0;
- it = queue.iterate();
- while (it.hasNext())
+ for (NodeEntry entry : queue)
{
- ne = (NodeEntry) it.next();
if (k <= 125)
{
- assertEquals(1, ne.getNumberOfNodeVisits());
+ assertEquals(1, entry.getNumberOfNodeVisits());
}
else
{
- assertEquals(2, ne.getNumberOfNodeVisits());
+ assertEquals(2, entry.getNumberOfNodeVisits());
}
k++;
}
@@ -140,17 +127,14 @@
public void testPrune() throws Exception
{
- for (int i = 0; i < 5000; i++)
+ for (int i = 0; i < 500; i++)
{
queue.addNodeEntry(new NodeEntry("/a/b/c/" + Integer.toString(i)));
}
- NodeEntry ne;
- Iterator it = queue.iterate();
int i = 0;
- while (it.hasNext())
+ for (NodeEntry ne : queue)
{
- ne = (NodeEntry) it.next();
if (i % 2 == 0)
{
queue.removeNodeEntry(ne);
@@ -158,17 +142,15 @@
i++;
}
- assertEquals(2500, queue.getNumberOfNodes());
+ assertEquals(250, queue.getNumberOfNodes());
- Set removalQueue = queue.getRemovalQueue();
- List evictionList = queue.getEvictionList();
+ Set<NodeEntry> removalQueue = queue.getRemovalQueue();
+ List<NodeEntry> evictionList = queue.getEvictionList();
- assertEquals(2500, removalQueue.size());
+ assertEquals(250, removalQueue.size());
- it = removalQueue.iterator();
- while (it.hasNext())
+ for (NodeEntry ne : removalQueue)
{
- ne = (NodeEntry) it.next();
int currentIndex = Integer.parseInt((String) ne.getFqn().get(3));
assertEquals(0, currentIndex % 2);
@@ -177,12 +159,12 @@
assertTrue(evictionList.contains(ne));
}
- assertEquals(5000, evictionList.size());
+ assertEquals(500, evictionList.size());
queue.prune();
assertEquals(0, removalQueue.size());
- assertEquals(2500, evictionList.size());
+ assertEquals(250, evictionList.size());
}
public void testGetFirstNodeEntry() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUAlgorithmTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -3,12 +3,9 @@
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.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
-import org.jboss.cache.RegionRegistry;
-import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
@@ -22,7 +19,8 @@
* @author Daniel Huang (dhuang(a)jboss.org)
*/
@Test(groups = "functional")
-public class LRUAlgorithmTest
+public class LRUAlgorithmTest extends EvictionTestsBase
+
{
RegionManager regionManager;
LRUAlgorithm algorithm;
@@ -32,16 +30,10 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- algorithm = new LRUAlgorithm();
- config = new LRUAlgorithmConfig();
-// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- // We have to setCache timeToLiveSeconds!!
- config.setTimeToLive(0);
-
regionManager = new RegionManagerImpl();
- ((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- Region r = regionManager.getRegion("/a/b", true);
- r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
+ config = new LRUAlgorithmConfig();
+ config.setTimeToLive(-1);
+ algorithm = (LRUAlgorithm) createAndAssignToRegion("/a/b", regionManager,
config);
}
/**
@@ -53,7 +45,6 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(1);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -79,7 +70,6 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -98,7 +88,6 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(1);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -124,14 +113,11 @@
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/d");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
- config.setMaxNodes(0);
- config.setTimeToLive(0);
+ config.setMaxNodes(-1);
+ config.setTimeToLive(-1);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
- TestingUtil.sleepThread(500);
-
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size should be ", 2,
algorithm.getEvictionQueue().getNumberOfNodes());
@@ -146,7 +132,6 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setTimeToLive(1000);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -172,7 +157,6 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(0);
config.setTimeToLive(1000);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -200,17 +184,16 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
- config.setMaxNodes(0);
- config.setTimeToLive(0);
- config.setMaxAge(1000);
+ config.setMaxNodes(-1);
+ config.setTimeToLive(-1);
+ config.setMaxAge(100);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(1100);
+ TestingUtil.sleepThread(110);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 0,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -226,21 +209,20 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
- config.setMaxNodes(0);
- config.setTimeToLive(0);
- config.setMaxAge(1000);
+ config.setMaxNodes(-1);
+ config.setTimeToLive(-1);
+ config.setMaxAge(100);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #1: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(500);
+ TestingUtil.sleepThread(50);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #2: ", 3,
algorithm.getEvictionQueue().getNumberOfNodes());
- TestingUtil.sleepThread(600);
+ TestingUtil.sleepThread(60);
algorithm.process(region.getEvictionEventQueue());
assertEquals("Queue size #3: ", 0,
algorithm.getEvictionQueue().getNumberOfNodes());
}
@@ -255,12 +237,11 @@
Fqn fqn3 = Fqn.fromString("/a/b/e");
Fqn fqn4 = Fqn.fromString("/a/b/f");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
// Should have a maximum of 2 nodes.
config.setMaxNodes(2);
- config.setTimeToLive(1000);
- config.setMaxAge(3000);
+ config.setTimeToLive(100);
+ config.setMaxAge(300);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn4, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -272,7 +253,7 @@
assert 2 == numNodesInQueue : "Queue size #1: expected 2 but was " +
numNodesInQueue;
// make sure all nodes now expire
- TestingUtil.sleepThread(1100);
+ TestingUtil.sleepThread(110);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
@@ -281,7 +262,7 @@
numNodesInQueue = eq.getNumberOfNodes();
assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " +
numNodesInQueue;
- TestingUtil.sleepThread(3100);
+ TestingUtil.sleepThread(310);
// visit the node now to prevent the idle time from doing the pruning - node still
gets pruned but by
// max age.
region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);
@@ -301,11 +282,10 @@
Fqn fqn2 = Fqn.fromString("/a/b/d");
Fqn fqn3 = Fqn.fromString("/a/b/e");
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxNodes(2);
- config.setTimeToLive(1000);
- config.setMaxAge(3000);
+ config.setTimeToLive(100);
+ config.setMaxAge(300);
region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn2, EvictionEvent.Type.REMOVE_NODE_EVENT);
@@ -317,7 +297,7 @@
assert 1 == numNodesInQueue : "Queue size #1: expected 1 but was " +
numNodesInQueue;
// make sure existing events all time out
- TestingUtil.sleepThread(1100);
+ TestingUtil.sleepThread(110);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
@@ -325,7 +305,7 @@
numNodesInQueue = eq.getNumberOfNodes();
assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " +
numNodesInQueue;
- TestingUtil.sleepThread(3100);
+ TestingUtil.sleepThread(310);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);
algorithm.process(region.getEvictionEventQueue());
@@ -337,7 +317,6 @@
public void testEvictionSortOrder() throws EvictionException
{
RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
- LRUAlgorithmConfig config = (LRUAlgorithmConfig)
region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
config.setMaxAge(1000000);
config.setMaxNodes(0);
@@ -400,5 +379,4 @@
{
System.out.println("-- " + msg);
}
-
-}
+}
\ No newline at end of file
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUConfigurationTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -7,6 +7,7 @@
package org.jboss.cache.eviction;
import org.jboss.cache.config.ConfigurationException;
+import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.element.EvictionElementParser;
import static org.testng.AssertJUnit.assertEquals;
@@ -30,15 +31,16 @@
String xml =
"<region name=\"/org/jboss/data\">\n" +
"<attribute
name=\"maxNodes\">5000</attribute>\n" +
- "<attribute
name=\"timeToLiveSeconds\">1000</attribute>\n" +
+ "<attribute
name=\"timeToLive\">1000</attribute>\n" +
"</region>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(5000, config.getMaxNodes());
- assertEquals(1000000, config.getTimeToLive());
+ assertEquals(1000, config.getTimeToLive());
}
public void testXMLParsing2() throws Exception
@@ -46,46 +48,36 @@
LRUAlgorithmConfig config = new LRUAlgorithmConfig();
String xml = "<region name=\"/maxAgeTest/\">\n" +
"<attribute
name=\"maxNodes\">10000</attribute>\n" +
- "<attribute
name=\"timeToLiveSeconds\">8</attribute>\n" +
- "<attribute
name=\"maxAgeSeconds\">10</attribute>\n" +
+ "<attribute
name=\"timeToLive\">1000</attribute>\n" +
+ "<attribute name=\"maxAge\">10</attribute>\n"
+
"</region>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(10000, config.getMaxNodes());
- assertEquals(8000, config.getTimeToLive());
- assertEquals(10000, config.getMaxAge());
+ assertEquals(1000, config.getTimeToLive());
+ assertEquals(10, config.getMaxAge());
}
public void testXMLParsing3() throws Exception
{
- LRUAlgorithmConfig config = new LRUAlgorithmConfig();
- String xml = "<region name=\"/maxAgeTest/\">\n" +
+ String xml = "<eviction wakeupInterval=\"30\"><region
name=\"/maxAgeTest/\">\n" +
"<attribute
name=\"maxNodes\">10000</attribute>\n" +
- "<attribute
name=\"maxAgeSeconds\">10</attribute>\n" +
- "</region>";
+ "<attribute name=\"maxAge\">10</attribute>\n"
+
+ "</region></eviction>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
boolean caught = false;
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionConfig ec = new EvictionElementParser().parseEvictionElement(element);
+ ec.getEvictionRegionConfigs().get(0).validate();
}
catch (ConfigurationException ce)
{
caught = true;
}
assertTrue("Configure exception should have been caught", caught);
-
- xml = "<region name=\"/maxAgeTest/\">\n" +
- "<attribute
name=\"timeToLiveSeconds\">8</attribute>\n" +
- "<attribute
name=\"maxAgeSeconds\">10</attribute>\n" +
- "</region>";
-
- element = XmlConfigHelper.stringToElementInCoreNS(xml);
-
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
-
- assertEquals(0, config.getMaxNodes());
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -1,7 +1,6 @@
package org.jboss.cache.eviction;
-import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -12,6 +11,8 @@
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionController;
+import org.jboss.cache.util.internals.EvictionWatcher;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -19,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
/**
* Unit tests for LRU Policy.
@@ -28,27 +30,30 @@
* @version $Revision$
*/
@Test(groups = "functional")
-public class LRUPolicyTest
+public class LRUPolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache;
- long wakeupIntervalMillis = 0;
- long dataRegionTTLMillis = 6000;
- long testRegionTTLMillis = 4000;
+ long wakeupIntervalMillis = 200;
+ long dataRegionTTLMillis = 200;
+ long testRegionTTLMillis = 200;
+ private int baseRegionMaxNodes = 10;
+ private int baseRegionTTLMillis = 200;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
- final long DURATION = 10000;
boolean isTrue;
+
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
Configuration conf =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
EvictionConfig evConfig = conf.getEvictionConfig();
- evConfig.setWakeupInterval(1000);
+ evConfig.setWakeupInterval(wakeupIntervalMillis);
List<EvictionRegionConfig> regionConfigs = new
ArrayList<EvictionRegionConfig>();
- regionConfigs.add(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
LRUAlgorithmConfig(dataRegionTTLMillis, 5)));
+ regionConfigs.add(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
LRUAlgorithmConfig(dataRegionTTLMillis, -1, 5)));
regionConfigs.add(new EvictionRegionConfig(Fqn.fromString("/test"), new
LRUAlgorithmConfig(testRegionTTLMillis, 10000)));
+ regionConfigs.add(new EvictionRegionConfig(Fqn.fromString("/base"), new
LRUAlgorithmConfig(baseRegionTTLMillis, -1, baseRegionMaxNodes)));
evConfig.setEvictionRegionConfigs(regionConfigs);
conf.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
conf.setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -93,7 +98,7 @@
cache.put(fqn, str, str);
}
- TestingUtil.sleepThread(wakeupIntervalMillis + 500);
+ new EvictionController(cache).startEviction();
for (int i = 0; i < 5; i++)
{
@@ -139,7 +144,7 @@
assertNull("Node should be empty ", val);
}
- public void testNodeVisited()
+ public void testNodeVisited() throws InterruptedException
{
String rootStr = "/org/jboss/test/data/";
@@ -152,26 +157,17 @@
cache.put(fqn, str, str);
}
- long period = (wakeupIntervalMillis / 2 + 500);
- System.out.println("-- sleeping for " + period + "ms");
- TestingUtil.sleepThread(period);
String str = rootStr + "7";
Fqn fqn = Fqn.fromString(str);
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);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, Fqn.fromString(rootStr + 3));
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);
+ new EvictionController(cache).startEviction(true);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, Fqn.fromString(rootStr + 7));
val = (String) cache.get(rootStr + "7", rootStr + "7");
System.out.println("-- val=" + val);
assertNull("Node should be empty ", val);
@@ -187,23 +183,21 @@
cache.put(fqn, str, str);
}
- long period = (wakeupIntervalMillis / 2 + 500);
- 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);
cache.get(fqn1, str1);// just to keep it fresh
cache.get(fqn2, str2);// just to keep it fresh
- TestingUtil.sleepThread(period);
+ new EvictionController(cache).startEviction();
cache.get(fqn1, str1);// just to keep it fresh
cache.get(fqn2, str2);// just to keep it fresh
- TestingUtil.sleepThread(period);
+ new EvictionController(cache).startEviction();
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);
+ new EvictionController(cache).startEviction();
val = (String) cache.get(rootStr + "7/7", rootStr + "7/7");
assertNull("Node should be empty ", val);
}
@@ -288,8 +282,8 @@
}
System.out.println("-- nodes/locks: " + cache.getNumberOfNodes() +
"/" + cache.getNumberOfLocksHeld());
TestingUtil.sleepThread(1000);
- if (counter > 10)
- {// run for 10 seconds
+ if (counter > 5)
+ {// run for 5 seconds
isTrue = false;
break;
}
@@ -333,19 +327,22 @@
public void testOvereviction() throws Exception
{
- Configuration c =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- Cache<Object, Object> cache1 = new DefaultCacheFactory<Object,
Object>().createCache(c, true);
- cache1.put(Fqn.fromString("/base/" + 0), "key",
"base" + 0);
- Node node = cache1.getRoot().getChild(Fqn.fromString("/base/"));
+ Node node = cache.getRoot().addChild(Fqn.fromString("/base/"));
node.setResident(true);
- cache1.getRoot().setResident(true);
+ cache.getRoot().setResident(true);
- for (int i = 1; i < 5100; i++)
+ EvictionWatcher ew = new EvictionWatcher(cache,
Fqn.fromString("/base/1"));
+
+ for (int i = 1; i < baseRegionMaxNodes + 2; i++)
{
- cache1.put(Fqn.fromString("/base/" + i), "key",
"base" + i);
+ Fqn f = Fqn.fromString("/base/" + i);
+ cache.put(f, "key", "base" + i);
}
- Thread.sleep(5000);
- assertEquals(5000,
cache1.getRoot().getChild(Fqn.fromString("/base")).getChildren().size());
+ new EvictionController(cache).startEviction();
+ assert ew.waitForEviction(30, TimeUnit.SECONDS);
+
+ assertEquals(baseRegionMaxNodes,
cache.getRoot().getChild(Fqn.fromString("/base")).getChildren().size());
+
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUAlgorithmTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -7,12 +7,9 @@
package org.jboss.cache.eviction;
import org.jboss.cache.Fqn;
-import org.jboss.cache.Region;
import org.jboss.cache.RegionImpl;
import org.jboss.cache.RegionManager;
import org.jboss.cache.RegionManagerImpl;
-import org.jboss.cache.RegionRegistry;
-import org.jboss.cache.config.EvictionRegionConfig;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -24,7 +21,7 @@
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class MRUAlgorithmTest
+public class MRUAlgorithmTest extends EvictionTestsBase
{
MRUAlgorithm algorithm;
RegionManager regionManager;
@@ -32,15 +29,10 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- algorithm = new MRUAlgorithm();
+ regionManager = new RegionManagerImpl();
MRUAlgorithmConfig config = new MRUAlgorithmConfig();
- // We have to set maxNodes explicitly!!
config.setMaxNodes(0);
-// config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
- regionManager = new RegionManagerImpl();
- ((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
- Region r = regionManager.getRegion("/a/b", true);
- r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), config));
+ algorithm = (MRUAlgorithm) createAndAssignToRegion("/a/b", regionManager,
config);
}
public void testMaxNodes() throws Exception
@@ -101,7 +93,7 @@
region.registerEvictionEvent(fqn9, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn10, EvictionEvent.Type.ADD_NODE_EVENT);
- Thread.sleep(5000);
+// Thread.sleep(5000);
assertEquals(8, algorithm.getEvictionQueue().getNumberOfNodes());
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUConfigurationTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -40,7 +40,8 @@
"</region>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(5000, config.getMaxNodes());
}
@@ -52,7 +53,8 @@
"</region>";
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(10000, config.getMaxNodes());
}
@@ -65,7 +67,8 @@
boolean caught = false;
try
{
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
}
catch (ConfigurationException ce)
{
@@ -79,7 +82,8 @@
element = XmlConfigHelper.stringToElementInCoreNS(xml);
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
assertEquals(10000, config.getMaxNodes());
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -34,7 +34,6 @@
long wakeupIntervalMillis = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
- final long DURATION = 10000;
boolean isTrue;
@BeforeMethod(alwaysRun = true)
@@ -62,10 +61,9 @@
{
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
EvictionConfig evConfig = config.getEvictionConfig();
- evConfig.setWakeupInterval(3000);
- evConfig.setDefaultEventQueueSize(200000);
+ evConfig.setWakeupInterval(200);
// root ERC
- evConfig.setDefaultEvictionRegionConfig(new EvictionRegionConfig(Fqn.ROOT, new
MRUAlgorithmConfig(100)));
+ evConfig.setDefaultEvictionRegionConfig(new EvictionRegionConfig(Fqn.ROOT, new
MRUAlgorithmConfig(100), 200000));
// new region ERC
evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/org/jboss/test/data"), new
MRUAlgorithmConfig(6)));
@@ -176,8 +174,8 @@
}
log("nodes/locks: " + cache.getNumberOfNodes() + "/" +
cache.getNumberOfLocksHeld());
TestingUtil.sleepThread(1000);
- if (counter > 10)
- {// run for 10 seconds
+ if (counter > 5)
+ {// run for 5 seconds
isTrue = false;
break;
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionConfigTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -43,6 +43,7 @@
{
Element element = XmlConfigHelper.stringToElementInCoreNS(xml);
NullEvictionAlgorithmConfig config = new NullEvictionAlgorithmConfig();
- EvictionElementParser.parseEvictionPolicyConfig(element, config, true);
+ EvictionElementParser.parseEvictionPolicyConfig(element, config);
+ config.validate();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/NullEvictionPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -10,15 +10,19 @@
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionWatcher;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
@Test(groups = {"functional"})
-public class NullEvictionPolicyTest
+public class NullEvictionPolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache;
@@ -45,11 +49,10 @@
* eviction thread to kick in, checks that nothing was evicted from the
* null policy regions but was from lru region.
*/
- public void testEviction()
+ public void testEviction() throws InterruptedException
{
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
- EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
NullEvictionAlgorithmConfig()), 1000);
- evConfig.setDefaultEventQueueSize(200000);
+ EvictionConfig evConfig = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
NullEvictionAlgorithmConfig(), 200000), 200);
evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/test"), new
NullEvictionAlgorithmConfig()));
evConfig.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/lru"), new LRUAlgorithmConfig(1000,
10000)));
config.setEvictionConfig(evConfig);
@@ -61,6 +64,9 @@
String testRootStr = "/test/";
String lruRootStr = "/lru/";
+ List<Fqn> toBeEvicted = new ArrayList<Fqn>();
+ for (int i = 0; i < 20; i++) toBeEvicted.add(Fqn.fromString(lruRootStr + i));
+ EvictionWatcher watcher = new EvictionWatcher(cache, toBeEvicted);
for (int i = 0; i < 20; i++)
{
Fqn dflt = Fqn.fromString(dfltRootStr + i);
@@ -70,7 +76,9 @@
cache.put(test, "key", "value");
cache.put(lru, "key", "value");
}
- TestingUtil.sleepThread(3500);
+
+ assert watcher.waitForEviction(30, TimeUnit.SECONDS);
+
for (int i = 0; i < 20; i++)
{
Fqn dflt = Fqn.fromString(dfltRootStr + i);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -8,17 +8,17 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.interceptors.EvictionInterceptor;
-import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionController;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import javax.transaction.TransactionManager;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.TimeUnit;
/**
* Tests the eviction and the possible lack of locking nodes.
@@ -29,22 +29,13 @@
* @author fhenning
*/
@Test(groups = {"functional"})
-public class OptimisticEvictionTest
+public class OptimisticEvictionTest extends EvictionTestsBase
{
-
- //Maximum number of runs 2^20
- private static final int NUMBER_OF_RUNS = 1 << 20;
- //Initial number of nodes
- private static final int NUMBER_NODES = 256;
-
- private Fqn region = Fqn.fromElements("testingRegion");
- private TransactionManager txManager;
private CacheSPI<Object, Object> cache;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- txManager = new DummyTransactionManagerLookup().getTransactionManager();
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
config.setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
config.setEvictionConfig(buildEvictionConfig());
@@ -53,59 +44,24 @@
private EvictionConfig buildEvictionConfig() throws Exception
{
- EvictionConfig result = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LRUAlgorithmConfig(0, 0, 10)), 1000);
+ EvictionConfig result = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LRUAlgorithmConfig(0, 0, 10)), 200);
result.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/testingRegion"), new LRUAlgorithmConfig(0,
0, 10)));
- result.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/timeBased"), new LRUAlgorithmConfig(1000,
1000, 10)));
+ result.addEvictionRegionConfig(new
EvictionRegionConfig(Fqn.fromString("/timeBased"), new LRUAlgorithmConfig(1, 1,
0)));
return result;
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- if (cache != null)
- {
- // shut down any existing gtx2EntryMap
- try
- {
- if (cache.getTransactionManager().getTransaction() != null)
- {
- cache.getTransactionManager().rollback();
- }
- }
- catch (Exception e)
- {
- // ignore
- }
- cache.stop();
- cache = null;
- }
+ TestingUtil.killCaches(cache);
}
-
- public void testEvictionError() throws Exception
- {
- //Initialize the cache via a map
- for (int i = 0; i < NUMBER_NODES; i++)
- {
- cache.put(Fqn.fromRelativeElements(region, i), i, i);
- }
-
- for (int i = 0; i < NUMBER_OF_RUNS; i++)
- {
- txManager.begin();
- cache.get(region, i % NUMBER_NODES);
- txManager.commit();
- }
- }
-
-
public void testEvictionOccurence() throws Exception
{
cache.put("/timeBased/test", "key", "value");
assertTrue(cache.exists("/timeBased/test"));
-
- // wait for it to be evicted.
- TestingUtil.sleepThread(3000);
+ new EvictionController(cache).startEviction();
+// assert waitForEviction(cache, 30, TimeUnit.SECONDS,
Fqn.fromString("/timeBased/test"));
assertTrue(!cache.exists("/timeBased/test"));
}
@@ -140,8 +96,10 @@
// Give eviction time to run a few times, then confirm parent
// is completely gone
- TestingUtil.sleepThread(5500);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, parent);
+ // wait for this twice since the first time will only clear the parent's
contents since a child exists.
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, parent);
+
assertFalse("Parent completely removed",
cache.getRoot().hasChild(parent));
}
-
}
Modified:
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -34,12 +34,13 @@
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.TimeUnit;
+
/**
* Unit tests for programmatic configuration of LRU policy
*
@@ -47,7 +48,7 @@
* @version $Revision$
*/
@Test(groups = {"functional"})
-public class ProgrammaticLRUPolicyTest
+public class ProgrammaticLRUPolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache;
long wakeupIntervalMillis = 0;
@@ -70,7 +71,7 @@
Configuration conf =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
CacheFactory<Object, Object> instance = new DefaultCacheFactory<Object,
Object>();
cache = (CacheSPI<Object, Object>) instance.createCache(conf, false);
- EvictionConfig erc = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LRUAlgorithmConfig(0, 0, 10)), 5000);
+ EvictionConfig erc = new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new
LRUAlgorithmConfig(0, 0, 10)), 200);
conf.setEvictionConfig(erc);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -87,7 +88,7 @@
private void addStringBasedRegion() throws Exception
{
- LRUAlgorithmConfig lru = new LRUAlgorithmConfig(4000, 0, 1000);
+ LRUAlgorithmConfig lru = new LRUAlgorithmConfig(150, 0, 1000);
EvictionRegionConfig regConfig = new
EvictionRegionConfig(Fqn.fromString("/dummy"), lru);
RegionManager regionManager = cache.getRegionManager();
@@ -114,7 +115,7 @@
assertNotNull("DataNode should be empty ", val);
System.out.println(cache.toString());
- TestingUtil.sleepThread(2 * wakeupIntervalMillis + 500);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, Fqn.fromString(rootStr + 3));
System.out.println(cache.toString());
val = (String) cache.get(rootStr + "3", rootStr + "3");
assertNull("DataNode should be empty ", val);
@@ -122,7 +123,7 @@
private void addObjectBasedRegion() throws Exception
{
- LRUAlgorithmConfig lru = new LRUAlgorithmConfig(4000, 1000);
+ LRUAlgorithmConfig lru = new LRUAlgorithmConfig(150, 1000);
EvictionRegionConfig regConfig = new EvictionRegionConfig(Fqn.fromElements(1),
lru);
RegionManager regionManager = cache.getRegionManager();
@@ -167,7 +168,7 @@
}
System.out.println(cache.toString());
- TestingUtil.sleepThread(2 * wakeupIntervalMillis + 500);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, fqn);
System.out.println(cache.toString());
try
@@ -215,13 +216,14 @@
fail("Failed to get" + e);
}
+ Integer in = 3;
+ Fqn fqn = Fqn.fromRelativeElements(rootfqn, in);
System.out.println(cache.toString());
- TestingUtil.sleepThread(2 * wakeupIntervalMillis + 500);
+ assert waitForEviction(cache, 30, TimeUnit.SECONDS, fqn);
+
System.out.println(cache.toString());
try
{
- Integer in = 3;
- Fqn fqn = Fqn.fromRelativeElements(rootfqn, in);
Object val = cache.get(fqn, in);
assertNull("DataNode should be empty ", val);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionTest.java 2008-08-18 13:34:16
UTC (rev 6574)
@@ -32,7 +32,7 @@
regionManager = new RegionManagerImpl();
((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null,
null, new RegionRegistry());
Region r = regionManager.getRegion("/a/b", true);//.setEvictionPolicy(new
DummyEvictionConfiguration());
- r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), new
NullEvictionAlgorithmConfig()));
+ r.setEvictionRegionConfig(new EvictionRegionConfig(r.getFqn(), new
LRUAlgorithmConfig()));
}
public void testAddedQueue() throws InterruptedException
@@ -46,7 +46,7 @@
region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
- assertEquals("AddedNode queue size ", 3, getQueueSize((RegionImpl)
region));
+ assertEquals("queue size ", 3, getQueueSize((RegionImpl) region));
EvictionEvent node = takeLastEvent((RegionImpl) region);
Fqn fqn = node.getFqn();
assertEquals("DataNode retrieved should be FILO ", fqn, fqn1);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -10,19 +10,23 @@
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.EvictionController;
+import org.jboss.cache.util.internals.EvictionWatcher;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.TimeUnit;
+
/**
* @author Ben Wang, Feb 11, 2004
*/
@Test(groups = {"functional"})
-public class ReplicatedLRUPolicyTest
+public class ReplicatedLRUPolicyTest extends EvictionTestsBase
{
CacheSPI<Object, Object> cache1, cache2, cache3;
- long wakeupIntervalMillis = 0;
+ long wakeupIntervalMillis = 200;
EvictionListener listener = new EvictionListener();
@BeforeMethod(alwaysRun = true)
@@ -31,21 +35,17 @@
cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC,
true), false);
cache1.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache1.getConfiguration().setUseRegionBasedMarshalling(true);
+
cache1.getConfiguration().getEvictionConfig().setWakeupInterval(wakeupIntervalMillis);
+
cache1.start();
cache1.getNotifier().addCacheListener(listener);
listener.resetCounter();
- cache3 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC),
false);
-
cache3.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ cache3 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object,
Object>().createCache(cache1.getConfiguration().clone(), false);
+
cache3.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache3.getConfiguration().setUseRegionBasedMarshalling(true);
+
cache3.getConfiguration().getEvictionConfig().setWakeupInterval(wakeupIntervalMillis);
cache3.start();
-
- wakeupIntervalMillis =
cache1.getConfiguration().getEvictionConfig().getWakeupInterval();
- log("wakeupInterval is " + wakeupIntervalMillis);
- if (wakeupIntervalMillis <= 0)
- {
- fail("testEviction(): eviction thread wake up interval is illegal " +
wakeupIntervalMillis);
- }
}
@AfterMethod(alwaysRun = true)
@@ -60,12 +60,16 @@
public void testBasic() throws Exception
{
String rootStr = "/org/jboss/test/data/";
+ LRUAlgorithmConfig cfg = (LRUAlgorithmConfig)
cache1.getConfiguration().getEvictionConfig().getEvictionRegionConfig(rootStr).getEvictionAlgorithmConfig();
+ cfg.setMaxAge(0);
+ cfg.setTimeToLive(0);
String str = rootStr + "0";
+ Fqn fqn = Fqn.fromString(str);
cache1.put(str, str, str);
-
- TestingUtil.sleepThread(30000);
- Object node = cache1.peek(Fqn.fromString(str), false);
- assertNull("DataNode should be evicted already ", node);
+// assert waitForEviction(cache1, 30, TimeUnit.SECONDS, fqn) : "Eviction event
not received!";
+ new EvictionController(cache1).startEviction();
+ Object node = cache1.peek(fqn, false);
+ assertNull("Node should be evicted already ", node);
assertEquals("Eviction counter ", 1, listener.getCounter());
String val = (String) cache3.get(str, str);
assertNotNull("DataNode should not be evicted here ", val);
@@ -75,6 +79,10 @@
public void testEviction() throws Exception
{
String rootStr = "/org/jboss/test/data/";
+ LRUAlgorithmConfig cfg = (LRUAlgorithmConfig)
cache3.getConfiguration().getEvictionConfig().getEvictionRegionConfig(rootStr).getEvictionAlgorithmConfig();
+ cfg.setMaxAge(60, TimeUnit.SECONDS);
+ cfg.setTimeToLive(360, TimeUnit.SECONDS);
+ EvictionWatcher ew = new EvictionWatcher(cache1, Fqn.fromString(rootStr + 3));
for (int i = 0; i < 10; i++)
{
String str = rootStr + i;
@@ -82,7 +90,8 @@
cache1.put(fqn, str, str);
}
- TestingUtil.sleepThread(2 * wakeupIntervalMillis);
+ assert ew.waitForEviction(30, TimeUnit.SECONDS);
+
String val = (String) cache1.get(rootStr + "3", rootStr +
"3");
assertNull("DataNode should be evicted already ", val);
val = (String) cache3.get(rootStr + "3", rootStr + "3");
@@ -92,6 +101,11 @@
public void testEvictionReplication() throws Exception
{
String rootStr = "/org/jboss/test/data/";
+ LRUAlgorithmConfig cfg = (LRUAlgorithmConfig)
cache3.getConfiguration().getEvictionConfig().getEvictionRegionConfig(rootStr).getEvictionAlgorithmConfig();
+ cfg.setMaxAge(60, TimeUnit.SECONDS);
+ cfg.setTimeToLive(360, TimeUnit.SECONDS);
+ EvictionWatcher ew = new EvictionWatcher(cache1, Fqn.fromString(rootStr + 3));
+
for (int i = 0; i < 10; i++)
{
String str = rootStr + i;
@@ -99,12 +113,12 @@
cache1.put(fqn, str, str);
}
- TestingUtil.sleepThread(wakeupIntervalMillis - 1000);
String str = rootStr + "7";
Fqn fqn = Fqn.fromString(str);
cache1.get(fqn, str);
- TestingUtil.sleepThread(wakeupIntervalMillis);
+ assert ew.waitForEviction(30, TimeUnit.SECONDS);
+
String val = (String) cache1.get(rootStr + "3", rootStr +
"3");
assertNull("DataNode should be empty ", val);
val = (String) cache3.get(rootStr + "7", rootStr + "7");
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/FIFOMinTTLTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -16,10 +16,10 @@
{
private Fqn fqn2 = Fqn.fromRelativeElements(region, "b");
private Thread busyThread;
- private boolean busyThreadRunning = true;
+ private volatile boolean busyThreadRunning = true;
@Override
- protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionAlgorithmConfig()
{
startBusyThread();
FIFOAlgorithmConfig cfg = new FIFOAlgorithmConfig();
@@ -33,6 +33,7 @@
busyThreadRunning = false;
try
{
+ busyThread.interrupt();
busyThread.join();
}
catch (InterruptedException e)
@@ -60,6 +61,7 @@
while (busyThreadRunning)
{
+ System.out.println("Busy thread working... ");
cache.put(fqn2, "k", "v");
TestingUtil.sleepRandom(150);
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LFUMinTTLTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -12,7 +12,7 @@
public class LFUMinTTLTest extends MinTTLTestBase
{
@Override
- protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionAlgorithmConfig()
{
return new LFUAlgorithmConfig();
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/minttl/LRUMinTTLTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -12,10 +12,10 @@
public class LRUMinTTLTest extends MinTTLTestBase
{
@Override
- protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionAlgorithmConfig()
{
LRUAlgorithmConfig cfg = new LRUAlgorithmConfig();
- cfg.setTimeToLive(1000);
+ cfg.setTimeToLive(200);
return cfg;
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java 2008-08-18
10:32:47 UTC (rev 6573)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MRUMinTTLTest.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -17,7 +17,7 @@
private Fqn fqn2 = Fqn.fromRelativeElements(region, "b");
@Override
- protected EvictionAlgorithmConfigBase getEvictionPolicyConfig()
+ protected EvictionAlgorithmConfigBase getEvictionAlgorithmConfig()
{
MRUAlgorithmConfig cfg = new MRUAlgorithmConfig();
cfg.setMaxNodes(1);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/eviction/minttl/MinTTLTestBase.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -6,12 +6,14 @@
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionAlgorithmConfigBase;
-import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.eviction.EvictionTestsBase;
+import org.jboss.cache.util.internals.EvictionController;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* This test exercises the minimum time to live for any element in the cache
@@ -20,17 +22,17 @@
* @since 2.1.0
*/
@Test(groups = {"functional"})
-public abstract class MinTTLTestBase
+public abstract class MinTTLTestBase extends EvictionTestsBase
{
// this should ideally be in an eviction test base class so all eviction policies can
be tested
- protected Cache cache;
+ protected Cache<Object, Object> cache;
protected Fqn region = Fqn.fromString("/test-region");
protected Fqn fqn = Fqn.fromRelativeElements(region, "a");
// allows the test methods to notify any support threads in subclasses that data is in
the cache and the test is about to begin
- protected CountDownLatch cacheInitialisedLatch;
+ protected volatile CountDownLatch cacheInitialisedLatch;
- protected abstract EvictionAlgorithmConfigBase getEvictionPolicyConfig();
+ protected abstract EvictionAlgorithmConfigBase getEvictionAlgorithmConfig();
@BeforeMethod
public void setUp()
@@ -38,7 +40,7 @@
cacheInitialisedLatch = new CountDownLatch(1);
// the LRU policy cfg
- EvictionAlgorithmConfigBase cfg = getEvictionPolicyConfig();
+ EvictionAlgorithmConfigBase cfg = getEvictionAlgorithmConfig();
// the region configuration
EvictionRegionConfig regionCfg = new EvictionRegionConfig();
@@ -47,7 +49,7 @@
regionCfg.setEvictionAlgorithmConfig(cfg);
// cache-wide
EvictionConfig ec = new EvictionConfig();
- ec.setWakeupInterval(1000);
+ ec.setWakeupInterval(200);
ec.addEvictionRegionConfig(regionCfg);
cache = new DefaultCacheFactory<Object, Object>().createCache(false);
@@ -60,7 +62,7 @@
cache.stop();
}
- public void testNoMinimumTTL()
+ public void testNoMinimumTTL() throws InterruptedException
{
cache.start();
cache.put(fqn, "k", "v");
@@ -69,14 +71,14 @@
assert cache.get(fqn, "k") != null : "Node should be in the
cache";
- TestingUtil.sleepThread(3000);
+ assert waitForEviction(cache, 10, TimeUnit.SECONDS, fqn);
assert cache.get(fqn, "k") == null : "Node should have been
evicted";
}
- public void testWithMinimumTTL()
+ public void testWithMinimumTTL() throws InterruptedException
{
- ((EvictionAlgorithmConfigBase)
cache.getConfiguration().getEvictionConfig().getEvictionRegionConfigs().get(0).getEvictionAlgorithmConfig()).setMinTimeToLive(3000);
+ ((EvictionAlgorithmConfigBase)
cache.getConfiguration().getEvictionConfig().getEvictionRegionConfigs().get(0).getEvictionAlgorithmConfig()).setMinTimeToLive(500);
cache.start();
cache.put(fqn, "k", "v");
@@ -85,15 +87,15 @@
assert cache.get(fqn, "k") != null : "Node should be in the
cache";
- TestingUtil.sleepThread(3000);
+ new EvictionController(cache).startEviction();
assert cache.get(fqn, "k") != null : "Node should still be in cache
due to a minTTL of 3 secs";
// the last cache.get() would have updated the last modified tstamp so we need to
wait at least 3 secs (+1 sec maybe for the eviction thread)
// to make sure this is evicted.
+ new EvictionController(cache).startEviction(true);
+ assert waitForEviction(cache, 5, TimeUnit.SECONDS, fqn);
- TestingUtil.sleepThread(5000);
-
assert cache.get(fqn, "k") == null : "Node should have been
evicted";
}
Modified: core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java 2008-08-18
10:32:47 UTC (rev 6573)
+++
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -24,12 +24,14 @@
public class EvictionController
{
CacheSPI cache;
+ RegionManager regionManager;
EvictionTimerTask timerTask;
+ long originalWakeupInterval;
public EvictionController(Cache cache)
{
this.cache = (CacheSPI) cache;
- RegionManager regionManager = this.cache.getRegionManager();
+ regionManager = this.cache.getRegionManager();
if (regionManager == null)
{
throw new IllegalStateException("Null region manager; is the cache
started?");
@@ -40,10 +42,21 @@
throw new IllegalStateException("No timer task!!!");
}
timerTask.stop();
+ originalWakeupInterval =
cache.getConfiguration().getEvictionConfig().getWakeupInterval();
}
public void startEviction()
{
+ startEviction(false);
+ }
+
+ /**
+ * Kick starts the eviction process
+ *
+ * @param restartEvictionTimerTask if true, restarts the eviction timer scheduled
executor after manually kicking off an eviction.
+ */
+ public void startEviction(boolean restartEvictionTimerTask)
+ {
try
{
Method method =
EvictionTimerTask.class.getDeclaredMethod("processRegions", new Class[]{});
@@ -55,6 +68,11 @@
e.printStackTrace();
throw new IllegalStateException(e);
}
+
+ if (restartEvictionTimerTask)
+ {
+ timerTask.init(originalWakeupInterval);
+ }
}
/**
Added: core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionWatcher.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionWatcher.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionWatcher.java 2008-08-18
13:34:16 UTC (rev 6574)
@@ -0,0 +1,71 @@
+package org.jboss.cache.util.internals;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeEvicted;
+import org.jboss.cache.notifications.event.NodeEvictedEvent;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Watches and waits for eviction events
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+@CacheListener
+public class EvictionWatcher
+{
+ Cache<?, ?> cache;
+ List<Fqn> fqnsToWaitFor;
+ CountDownLatch latch;
+
+ public EvictionWatcher(Cache<?, ?> cache, Fqn... fqnsToWaitFor)
+ {
+ this(cache, Arrays.asList(fqnsToWaitFor));
+ }
+
+ public EvictionWatcher(Cache<?, ?> cache, List<Fqn> fqnsToWaitFor)
+ {
+ this.cache = cache;
+ this.fqnsToWaitFor = new ArrayList<Fqn>(fqnsToWaitFor);
+ latch = new CountDownLatch(fqnsToWaitFor.size());
+ cache.addCacheListener(this);
+ }
+
+ @NodeEvicted
+ public void receive(NodeEvictedEvent ee)
+ {
+ boolean xpect = false;
+ if (ee.isPre() && fqnsToWaitFor.contains(ee.getFqn()))
+ {
+ xpect = true;
+ fqnsToWaitFor.remove(ee.getFqn());
+ latch.countDown();
+ }
+
+ if (ee.isPre()) System.out.println("Saw " + ee.getFqn() + " was
expecting? " + xpect);
+ }
+
+ /**
+ * Blocks for an eviction event to happen on all the configured Fqns to wait for.
+ *
+ * @return true if the eviction events occured, false if we timed out.
+ */
+ public boolean waitForEviction(long timeout, TimeUnit unit) throws
InterruptedException
+ {
+ try
+ {
+ return latch.await(timeout, unit);
+ }
+ finally
+ {
+ cache.removeCacheListener(this);
+ }
+ }
+}
Modified: core/trunk/src/test/resources/configs/string-property-replaced.xml
===================================================================
--- core/trunk/src/test/resources/configs/string-property-replaced.xml 2008-08-18 10:32:47
UTC (rev 6573)
+++ core/trunk/src/test/resources/configs/string-property-replaced.xml 2008-08-18 13:34:16
UTC (rev 6574)
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
-<jbosscache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:jboss:jbosscache-core:config:3.0">
+<jbosscache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:noNamespaceSchemaLocation="http://www.jboss.org/jbosscache/jboss...
<locking
lockAcquisitionTimeout="${test.property.LockAcquisitionTimeout:15000}"
nodeLockingScheme="${test.property.NodeLockingScheme:OPTIMISTIC}"/>
<transaction syncCommitPhase="${test.property.SyncCommitPhase:true}"
syncRollbackPhase="true"/>
<serialization useRegionBasedMarshalling="true"/>
- <stateRetrieval fetchInMemoryState="false" timeout="20000"/>
+ <stateRetrieval fetchInMemoryState="false"
timeout="20000"/>
<startup regionsInactiveOnStartup="true"/>
<transport clusterName="optimistic-entity"
multiplexerStack="udp-sync">
<jgroupsConfig/>