JBoss Cache SVN: r5900 - support/trunk/common.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 12:27:02 -0400 (Wed, 28 May 2008)
New Revision: 5900
Modified:
support/trunk/common/pom.xml
Log:
Modified: support/trunk/common/pom.xml
===================================================================
--- support/trunk/common/pom.xml 2008-05-28 16:26:55 UTC (rev 5899)
+++ support/trunk/common/pom.xml 2008-05-28 16:27:02 UTC (rev 5900)
@@ -25,8 +25,8 @@
</license>
</licenses>
<scm>
- <connection>scm:svn:http://anonsvn.jboss.org/repos/jbosscache/core/trunk/</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/jbosscache/core/trunk</developerConnection>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/jbosscache</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/jbosscache</developerConnection>
<url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbosscache/</url>
</scm>
<issueManagement>
@@ -34,8 +34,8 @@
<url>http://jira.jboss.com/jira/browse/JBCACHE</url>
</issueManagement>
<ciManagement>
- <system>cruisecontrol</system>
- <url>http://cruisecontrol.jboss.com/cc/</url>
+ <system>hudson</system>
+ <url>http://hudson.qa.jboss.com/hudson/view/JBoss%20Cache/</url>
<notifiers>
<notifier>
<type>mail</type>
@@ -122,23 +122,6 @@
</archive>
</configuration>
</plugin>
- <!-- EMMA for code coverage -->
- <!--
- Commented out until we have this working properly
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>emma-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
- <inherited>true</inherited>
- <executions>
- <execution>
- <goals>
- <goal>instrument</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -167,14 +150,6 @@
<!-- This seems to fail in some cases on 2.3 as well, disable for now -->
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<reportFormat>xml</reportFormat>
- <!--
- Commented out until we have this working properly
- <classesDirectory>${project.build.directory}/emma-classes</classesDirectory>
- -->
- <!--
- <parallel>true</parallel>
- <threadCount>20</threadCount>
- -->
</configuration>
</plugin>
@@ -280,15 +255,6 @@
<xmlOutputDirectory>target</xmlOutputDirectory>
</configuration>
</plugin>
-<!-- EMMA report -->
-<!--
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>emma-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
- <inherited>true</inherited>
- </plugin>
--->
</plugins>
</reporting>
<properties>
@@ -358,6 +324,70 @@
<!-- Profiles, used for test permutations -->
<profiles>
<profile>
+ <!-- EMMA for code coverage -->
+ <id>codeCoverage</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>emma-maven-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <inherited>true</inherited>
+ <executions>
+ <execution>
+ <goals>
+ <goal>instrument</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- override the surefire plugin with this stuff -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.3</version>
+ <inherited>true</inherited>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>bind.address</name>
+ <value>127.0.0.1</value>
+ </property>
+ <property>
+ <name>jgroups.stack</name>
+ <value>udp</value>
+ </property>
+ <property>
+ <name>java.net.preferIPv4Stack</name>
+ <value>true</value>
+ </property>
+ </systemProperties>
+ <groups>${defaultTestGroup}</groups>
+ <forkMode>always</forkMode>
+ <!-- increasing JVM heap size -->
+ <argLine>-Xmx1024M</argLine>
+ <!-- Warning, this does not work right on 2.4-SNAPSHOT, (see SUREFIRE-349) -->
+ <!-- This seems to fail in some cases on 2.3 as well, disable for now -->
+ <redirectTestOutputToFile>false</redirectTestOutputToFile>
+ <reportFormat>xml</reportFormat>
+ <classesDirectory>${project.build.directory}/emma-classes</classesDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <!-- EMMA report -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>emma-maven-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <inherited>true</inherited>
+ </plugin>
+ </plugins>
+ </reporting>
+ </profile>
+ <profile>
<id>jgroups-tcp</id>
<build>
<plugins>
16 years, 7 months
JBoss Cache SVN: r5899 - core/trunk.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 12:26:55 -0400 (Wed, 28 May 2008)
New Revision: 5899
Modified:
core/trunk/README-Maven.txt
core/trunk/pom.xml
Log:
Better code coverage integration
Modified: core/trunk/README-Maven.txt
===================================================================
--- core/trunk/README-Maven.txt 2008-05-28 15:14:41 UTC (rev 5898)
+++ core/trunk/README-Maven.txt 2008-05-28 16:26:55 UTC (rev 5899)
@@ -35,7 +35,10 @@
username and password set up. (Deploys snapshots to http://snapshots.jboss.org/maven2/org/jboss/cache/). If you have
a non-SNAPSHOT version number in your pom.xml, it will be deployed to the live releases repository (see below)
+* mvn clean site -Ptest-functional,code-coverage: will run all tests in the test-functional profile and generate code
+ coverage reports using EMMA.
+
1.2. Setting up your WebDAV username and password to deploy project snapshots
-----------------------------------------------------------------------------
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2008-05-28 15:14:41 UTC (rev 5898)
+++ core/trunk/pom.xml 2008-05-28 16:26:55 UTC (rev 5899)
@@ -21,6 +21,7 @@
<version>${jbosscache-core-version}</version>
<name>JBoss Cache - Core Edition</name>
<description>JBoss Cache - Core Edition</description>
+ <url>http://www.jbosscache.org</url>
<packaging>jar</packaging>
<dependencies>
<dependency>
@@ -34,7 +35,14 @@
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
+
<dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-core</artifactId>
<version>2.2.3.GA</version>
16 years, 7 months
JBoss Cache SVN: r5898 - core/trunk/src/main/java/org/jboss/cache/config.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 11:14:41 -0400 (Wed, 28 May 2008)
New Revision: 5898
Added:
core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java
Modified:
core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
Log:
JBCACHE-1138: User extensible configuration should be centralised - configuration settings allowing <class> and <properties> defintions
Modified: core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java 2008-05-28 14:54:46 UTC (rev 5897)
+++ core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java 2008-05-28 15:14:41 UTC (rev 5898)
@@ -170,77 +170,39 @@
return clone;
}
- public static class BuddyLocatorConfig extends ConfigurationComponent
+ public static class BuddyLocatorConfig extends PluggableConfigurationComponent
{
private static final long serialVersionUID = -8003634097931826091L;
- private String buddyLocatorClass = NextMemberBuddyLocator.class.getName();
- private Properties buddyLocatorProperties;
+ public BuddyLocatorConfig()
+ {
+ // default
+ className = NextMemberBuddyLocator.class.getName();
+ }
public String getBuddyLocatorClass()
{
- return buddyLocatorClass;
+ return className;
}
public void setBuddyLocatorClass(String buddyLocatorClass)
{
- testImmutability("buddyLocatorClass");
- this.buddyLocatorClass = buddyLocatorClass;
- if (buddyLocatorClass == null)
- this.buddyLocatorClass = NextMemberBuddyLocator.class.getName();
+ setClassName(buddyLocatorClass);
}
public Properties getBuddyLocatorProperties()
{
- return buddyLocatorProperties;
+ return properties;
}
public void setBuddyLocatorProperties(Properties buddyLocatorProperties)
{
- testImmutability("buddyLocatorProperties");
- this.buddyLocatorProperties = buddyLocatorProperties;
+ setProperties(buddyLocatorProperties);
}
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
-
- if (obj instanceof BuddyLocatorConfig)
- {
- BuddyLocatorConfig other = (BuddyLocatorConfig) obj;
- return (Util.safeEquals(this.buddyLocatorClass, other.buddyLocatorClass)
- && Util.safeEquals(this.buddyLocatorProperties, other.buddyLocatorProperties));
- }
- return false;
- }
-
- @Override
- public int hashCode()
- {
- int result = 19;
- result = 41 * result + (buddyLocatorClass == null ? 0 : buddyLocatorClass.hashCode());
- result = 41 * result + (buddyLocatorProperties == null ? 0 : buddyLocatorProperties.hashCode());
- return result;
- }
-
- @Override
- public String toString()
- {
- return super.toString() + " class=" + buddyLocatorClass +
- " properties=" + buddyLocatorProperties;
- }
-
- @Override
public BuddyLocatorConfig clone() throws CloneNotSupportedException
{
- BuddyLocatorConfig clone = (BuddyLocatorConfig) super.clone();
- if (buddyLocatorProperties != null)
- clone.buddyLocatorProperties = (Properties) buddyLocatorProperties.clone();
- return clone;
+ return (BuddyLocatorConfig) super.clone();
}
-
-
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2008-05-28 14:54:46 UTC (rev 5897)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2008-05-28 15:14:41 UTC (rev 5898)
@@ -9,10 +9,7 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.SingletonStoreCacheLoader;
import org.jboss.cache.util.Util;
-import org.jboss.cache.xml.XmlHelper;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -170,19 +167,16 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
* @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
*/
- public static class IndividualCacheLoaderConfig extends ConfigurationComponent
+ public static class IndividualCacheLoaderConfig extends PluggableConfigurationComponent
{
private static final long serialVersionUID = -2282396799100828593L;
- private String className;
private boolean async;
private boolean ignoreModifications;
private boolean fetchPersistentState;
private boolean purgeOnStartup;
- private Properties properties;
-
private SingletonStoreConfig singletonStoreConfig;
private transient CacheLoader cacheLoader;
@@ -215,17 +209,6 @@
this.fetchPersistentState = fetchPersistentState;
}
- public void setClassName(String className)
- {
- testImmutability("className");
- this.className = className;
- }
-
- public String getClassName()
- {
- return className;
- }
-
public void setAsync(boolean async)
{
testImmutability("async");
@@ -248,31 +231,6 @@
return ignoreModifications;
}
- public void setProperties(String properties) throws IOException
- {
- if (properties == null) return;
-
- testImmutability("properties");
- // JBCACHE-531: escape all backslash characters
- // replace any "\" that is not preceded by a backslash with "\\"
- properties = XmlHelper.escapeBackslashes(properties);
- ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
- this.properties = new Properties();
- this.properties.load(is);
- is.close();
- }
-
- public void setProperties(Properties properties)
- {
- testImmutability("properties");
- this.properties = properties;
- }
-
- public Properties getProperties()
- {
- return properties;
- }
-
public void setPurgeOnStartup(boolean purgeOnStartup)
{
testImmutability("purgeOnStartup");
@@ -318,11 +276,12 @@
@Override
public boolean equals(Object obj)
{
- if (!(obj instanceof IndividualCacheLoaderConfig))
- return false;
- IndividualCacheLoaderConfig i = (IndividualCacheLoaderConfig) obj;
- return equalsExcludingProperties(i)
- && Util.safeEquals(this.properties, i.properties);
+ if (super.equals(obj))
+ {
+ IndividualCacheLoaderConfig i = (IndividualCacheLoaderConfig) obj;
+ return equalsExcludingProperties(i);
+ }
+ return false;
}
protected boolean equalsExcludingProperties(Object obj)
@@ -374,8 +333,6 @@
public IndividualCacheLoaderConfig clone() throws CloneNotSupportedException
{
IndividualCacheLoaderConfig clone = (IndividualCacheLoaderConfig) super.clone();
- if (properties != null)
- clone.properties = (Properties) properties.clone();
if (singletonStoreConfig != null)
clone.setSingletonStoreConfig(singletonStoreConfig.clone());
clone.cacheLoader = cacheLoader;
@@ -385,7 +342,7 @@
/**
* Configuration for a SingletonStoreCacheLoader
*/
- public static class SingletonStoreConfig extends ConfigurationComponent
+ public static class SingletonStoreConfig extends PluggableConfigurationComponent
{
private static final long serialVersionUID = 824251894176131850L;
@@ -394,19 +351,10 @@
*/
private boolean singletonStoreEnabled;
- /**
- * Class implementing the singleton store functionality.
- */
- private String singletonStoreClass;
-
- /**
- * Properties of the singleton store.
- */
- private Properties singletonStoreproperties;
-
public SingletonStoreConfig()
{
- singletonStoreClass = SingletonStoreCacheLoader.class.getName();
+ // default value
+ className = SingletonStoreCacheLoader.class.getName();
}
public boolean isSingletonStoreEnabled()
@@ -422,27 +370,22 @@
public String getSingletonStoreClass()
{
- return singletonStoreClass;
+ return className;
}
- public void setSingletonStoreClass(String singletonStoreClass)
+ public void setSingletonStoreClass(String className)
{
- testImmutability("singletonStoreClass");
- if (!singletonStoreClass.equals(""))
- {
- this.singletonStoreClass = singletonStoreClass;
- }
+ setClassName(className);
}
public Properties getSingletonStoreproperties()
{
- return singletonStoreproperties;
+ return properties;
}
- public void setSingletonStoreproperties(Properties singletonStoreproperties)
+ public void setSingletonStoreproperties(Properties properties)
{
- testImmutability("singletonStoreproperties");
- this.singletonStoreproperties = singletonStoreproperties;
+ setProperties(properties);
}
@Override
@@ -451,12 +394,10 @@
if (this == obj)
return true;
- if (obj instanceof SingletonStoreConfig)
+ if (super.equals(obj))
{
SingletonStoreConfig other = (SingletonStoreConfig) obj;
- return ((this.singletonStoreEnabled == other.singletonStoreEnabled)
- && Util.safeEquals(this.singletonStoreClass, other.singletonStoreClass)
- && Util.safeEquals(this.singletonStoreproperties, other.singletonStoreproperties));
+ return this.singletonStoreEnabled == other.singletonStoreEnabled;
}
return false;
}
@@ -465,9 +406,8 @@
public int hashCode()
{
int result = 19;
+ result = 41 * result + super.hashCode();
result = 41 * result + (singletonStoreEnabled ? 0 : 1);
- result = 41 * result + (singletonStoreClass == null ? 0 : singletonStoreClass.hashCode());
- result = 41 * result + (singletonStoreproperties == null ? 0 : singletonStoreproperties.hashCode());
return result;
}
@@ -475,17 +415,14 @@
public String toString()
{
return super.toString() + " enabled=" + singletonStoreEnabled +
- " class=" + singletonStoreClass +
- " properties=" + singletonStoreproperties;
+ " class=" + className +
+ " properties=" + properties;
}
@Override
public SingletonStoreConfig clone() throws CloneNotSupportedException
{
- SingletonStoreConfig clone = (SingletonStoreConfig) super.clone();
- if (singletonStoreproperties != null)
- clone.singletonStoreproperties = (Properties) singletonStoreproperties.clone();
- return clone;
+ return (SingletonStoreConfig) super.clone();
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2008-05-28 14:54:46 UTC (rev 5897)
+++ core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2008-05-28 15:14:41 UTC (rev 5898)
@@ -28,7 +28,7 @@
* @version $Revision$
* @see #testImmutability(String)
*/
-public class ConfigurationComponent implements Serializable, Cloneable
+public abstract class ConfigurationComponent implements Serializable, Cloneable
{
private static final long serialVersionUID = 4879873994727821938L;
Added: core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/config/PluggableConfigurationComponent.java 2008-05-28 15:14:41 UTC (rev 5898)
@@ -0,0 +1,91 @@
+package org.jboss.cache.config;
+
+import org.jboss.cache.xml.XmlHelper;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * A configuration component where the implementation class can be specified, and comes with its own set of properties.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.2.0
+ */
+public abstract class PluggableConfigurationComponent extends ConfigurationComponent
+{
+ protected String className;
+ protected Properties properties;
+
+ public String getClassName()
+ {
+ return className;
+ }
+
+ public void setClassName(String className)
+ {
+ testImmutability("className");
+ this.className = className;
+ }
+
+ public Properties getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperties(Properties properties)
+ {
+ testImmutability("properties");
+ this.properties = properties;
+ }
+
+ public void setProperties(String properties) throws IOException
+ {
+ if (properties == null) return;
+
+ testImmutability("properties");
+ // JBCACHE-531: escape all backslash characters
+ // replace any "\" that is not preceded by a backslash with "\\"
+ properties = XmlHelper.escapeBackslashes(properties);
+ ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
+ this.properties = new Properties();
+ this.properties.load(is);
+ is.close();
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ PluggableConfigurationComponent that = (PluggableConfigurationComponent) o;
+
+ if (className != null ? !className.equals(that.className) : that.className != null) return false;
+ if (properties != null ? !properties.equals(that.properties) : that.properties != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (className != null ? className.hashCode() : 0);
+ result = 31 * result + (properties != null ? properties.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName() + " {className = " + className +
+ ", properties=" + properties + "}";
+ }
+
+ @Override
+ public PluggableConfigurationComponent clone() throws CloneNotSupportedException
+ {
+ PluggableConfigurationComponent clone = (PluggableConfigurationComponent) super.clone();
+ if (properties != null) clone.properties = (Properties) properties.clone();
+ return clone;
+ }
+}
16 years, 7 months
JBoss Cache SVN: r5897 - core/trunk/src/main/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 10:54:46 -0400 (Wed, 28 May 2008)
New Revision: 5897
Modified:
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
Log:
JBCACHE-1353: State transfer for Buddy Replication does not use configured state transfer timeouts or lock acquisition timeouts
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-05-28 14:49:35 UTC (rev 5896)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-05-28 14:54:46 UTC (rev 5897)
@@ -8,8 +8,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DataContainerImpl;
-import org.jboss.cache.*;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.RPCManager;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
import org.jboss.cache.commands.ReplicableCommand;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand;
@@ -498,7 +504,7 @@
}
if (log.isInfoEnabled()) log.info("Removing self from buddy group " + groupName);
-
+
for (Map.Entry<Address, String> me : buddyPool.entrySet())
{
if (me.getValue().equals(groupName))
@@ -867,7 +873,7 @@
{
// Call _getState with progressively longer timeouts until we
// get state or it doesn't throw a TimeoutException
- long[] timeouts = {400, 800, 1600};
+ long[] timeouts = {400, 800, 1600, configuration.getStateRetrievalTimeout()};
TimeoutException timeoutException = null;
for (int i = 0; i < timeouts.length; i++)
16 years, 7 months
JBoss Cache SVN: r5896 - in core/trunk/src/main/java/org/jboss/cache: lock and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 10:49:35 -0400 (Wed, 28 May 2008)
New Revision: 5896
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java
core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java
Log:
Minor refactoring
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-28 13:38:24 UTC (rev 5895)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-28 14:49:35 UTC (rev 5896)
@@ -27,18 +27,21 @@
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.base.PostProcessingCommandInterceptor;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockManager;
import static org.jboss.cache.lock.LockType.READ;
import static org.jboss.cache.lock.LockType.WRITE;
+import org.jboss.cache.lock.LockUtil;
import org.jboss.cache.lock.PessimisticNodeBasedLockManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
/*
* // TODO: 2.2.0: refactorings ideas
@@ -61,12 +64,14 @@
{
private DataContainerImpl dataContainer;
private PessimisticNodeBasedLockManager lockManager;
+ private CommandsFactory commandsFactory;
@Inject
- public void injectDependencies(DataContainerImpl dataContainer, LockManager lockManager)
+ public void injectDependencies(DataContainerImpl dataContainer, LockManager lockManager, CommandsFactory commandsFactory)
{
this.dataContainer = dataContainer;
this.lockManager = (PessimisticNodeBasedLockManager) lockManager;
+ this.commandsFactory = commandsFactory;
}
@Override
@@ -101,7 +106,7 @@
Fqn childFqn = Fqn.fromElements(childName);
NodeSPI childNode = n.getChildDirect(childFqn);
if (childNode == null) childNode = n.addChildDirect(childFqn);
- lockManager.manageReverseRemove(ctx, childNode, true, null);
+ LockUtil.manageReverseRemove(ctx, childNode, true, null, commandsFactory);
n = childNode;
}
}
@@ -222,7 +227,7 @@
}
}
- lockManager.lockAllForRemoval(dataContainer.peek(command.getFqn(), false, false), ctx, entry);
+ lockAllForRemoval(dataContainer.peek(command.getFqn(), false, false), ctx, entry);
if (!createdNodes.isEmpty())
{
@@ -248,6 +253,35 @@
return created ? false : retVal;
}
+ /**
+ * Acquires write locks on the node and all child nodes, adding children to the list of removed nodes in the context.
+ *
+ * @param node node to inspect
+ * @param ctx invocation context
+ * @param entry transaction entry
+ * @throws InterruptedException in the event of interruption
+ */
+ public void lockAllForRemoval(NodeSPI node, InvocationContext ctx, TransactionEntry entry) throws InterruptedException
+ {
+ if (node == null) return;
+ // lock node
+ lockManager.lockAndRecord(node, WRITE, ctx);
+
+ // add to deleted list
+ if (entry != null) entry.addRemovedNode(node.getFqn());
+
+ // now children.
+ Map<Object, NodeSPI> children = node.getChildrenMapDirect();
+ if (children != null)
+ {
+ for (NodeSPI child : children.values())
+ {
+ // lock child.
+ lockAllForRemoval(child, ctx, entry);
+ }
+ }
+ }
+
@Override
protected Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
{
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java 2008-05-28 13:38:24 UTC (rev 5895)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockUtil.java 2008-05-28 14:49:35 UTC (rev 5896)
@@ -2,14 +2,22 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import javax.transaction.Status;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public abstract class LockUtil
{
@@ -199,4 +207,30 @@
return status;
}
+ /**
+ * Test if this node needs to be 'undeleted'
+ * reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put()
+ */
+ public static void manageReverseRemove(InvocationContext ctx, NodeSPI childNode, boolean reverseRemoveCheck, List createdNodes, CommandsFactory commandsFactory)
+ {
+ if (ctx.getGlobalTransaction() != null) //if no tx then reverse remove does not make sense
+ {
+ Fqn fqn = childNode.getFqn();
+ TransactionEntry entry = ctx.getTransactionEntry();
+ boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && entry != null && entry.getRemovedNodes().contains(fqn);
+ if (!needToReverseRemove) return;
+ childNode.markAsDeleted(false);
+ //if we'll rollback the tx data should be added to the node again
+ Map oldData = new HashMap(childNode.getDataDirect());
+ PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(ctx.getGlobalTransaction(), fqn, oldData);
+ // txTable.get(gtx).addUndoOperation(command); --- now need to make sure this is added to the normal mods list instead
+ entry.addModification(command);
+ //we're prepared for rollback, now reset the node
+ childNode.clearDataDirect();
+ if (createdNodes != null)
+ {
+ createdNodes.add(childNode);
+ }
+ }
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java 2008-05-28 13:38:24 UTC (rev 5895)
+++ core/trunk/src/main/java/org/jboss/cache/lock/PessimisticNodeBasedLockManager.java 2008-05-28 14:49:35 UTC (rev 5896)
@@ -5,18 +5,13 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.write.PutDataMapCommand;
import org.jboss.cache.factories.CommandsFactory;
import org.jboss.cache.factories.annotations.Inject;
import static org.jboss.cache.lock.LockType.WRITE;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
/**
* Contains specific methods for the PessimisticLockInterceptor.
@@ -152,7 +147,7 @@
// actually acquire the lock we need. This method blocks.
acquireNodeLock(ctx, currentNode, owner, gtx, lockTypeRequired, timeout);
- manageReverseRemove(ctx, currentNode, reverseRemoveCheck, createdNodes);
+ LockUtil.manageReverseRemove(ctx, currentNode, reverseRemoveCheck, createdNodes, commandsFactory);
// make sure the lock we acquired isn't on a deleted node/is an orphan!!
// look into invalidated nodes as well
NodeSPI repeek = dataContainer.peek(currentNodeFqn, true, true);
@@ -255,62 +250,4 @@
}
}
}
-
- /**
- * Test if this node needs to be 'undeleted'
- * reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put()
- */
- public void manageReverseRemove(InvocationContext ctx, NodeSPI childNode, boolean reverseRemoveCheck, List createdNodes)
- {
- if (ctx.getGlobalTransaction() != null) //if no tx then reverse remove does not make sense
- {
- Fqn fqn = childNode.getFqn();
- TransactionEntry entry = ctx.getTransactionEntry();
- boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && entry != null && entry.getRemovedNodes().contains(fqn);
- if (!needToReverseRemove) return;
- childNode.markAsDeleted(false);
- //if we'll rollback the tx data should be added to the node again
- Map oldData = new HashMap(childNode.getDataDirect());
- PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(ctx.getGlobalTransaction(), fqn, oldData);
- // txTable.get(gtx).addUndoOperation(command); --- now need to make sure this is added to the normal mods list instead
- entry.addModification(command);
- //we're prepared for rollback, now reset the node
- childNode.clearDataDirect();
- if (createdNodes != null)
- {
- createdNodes.add(childNode);
- }
- }
- }
-
- /**
- * Acquires write locks on the node and all child nodes, adding children to the list of removed nodes in the context.
- *
- * @param node node to inspect
- * @param ctx invocation context
- * @param entry transaction entry
- * @throws InterruptedException in the event of interruption
- */
- public void lockAllForRemoval(NodeSPI node, InvocationContext ctx, TransactionEntry entry) throws InterruptedException
- {
- if (node == null) return;
-
- long timeout = ctx.getContextLockAcquisitionTimeout(lockAcquisitionTimeout);
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- Object owner = (gtx != null) ? gtx : Thread.currentThread();
-
- Set<NodeLock> acquiredLocks = node.getLock().acquireAll(owner, timeout, WRITE);
- if (acquiredLocks.size() > 0)
- {
- if (gtx != null)
- {
- ctx.getTransactionEntry().addLocks(acquiredLocks);
- for (NodeLock l : acquiredLocks) entry.addRemovedNode(l.getFqn());
- }
- else
- {
- ctx.addInvocationLocksAcquired(acquiredLocks);
- }
- }
- }
}
16 years, 7 months
JBoss Cache SVN: r5895 - core/trunk/src/main/java/org/jboss/cache/transaction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 09:38:24 -0400 (Wed, 28 May 2008)
New Revision: 5895
Modified:
core/trunk/src/main/java/org/jboss/cache/transaction/GenericTransactionManagerLookup.java
Log:
JBCACHE-1354 - proper detection of transaction manager on Glassfish
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/GenericTransactionManagerLookup.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/GenericTransactionManagerLookup.java 2008-05-28 13:31:13 UTC (rev 5894)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/GenericTransactionManagerLookup.java 2008-05-28 13:38:24 UTC (rev 5895)
@@ -54,8 +54,8 @@
{
{"java:/TransactionManager", "JBoss, JRun4"},
{"java:comp/TransactionManager", "Resin 3.x"},
+ {"java:appserver/TransactionManager", "Sun Glassfish"},
{"java:pm/TransactionManager", "Borland, Sun"},
- {"java:appserver/TransactionManager", "Sun Glassfish"},
{"javax.transaction.TransactionManager", "BEA WebLogic"},
{"java:comp/UserTransaction", "Resin, Orion, JOnAS (JOTM)"},
};
16 years, 7 months
JBoss Cache SVN: r5894 - in core/trunk/src: test/java/org/jboss/cache/buddyreplication and 9 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 09:31:13 -0400 (Wed, 28 May 2008)
New Revision: 5894
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java
core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java
Log:
Refactored tests so they dont use deprecated code
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockManager.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -241,6 +241,15 @@
boolean isLocked(NodeSPI n);
/**
+ * Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.
+ *
+ * @param n node to inspect
+ * @param lockType lockType to test for
+ * @return true of locked; false if not.
+ */
+ boolean isLocked(NodeSPI n, LockType lockType);
+
+ /**
* Retrieves the write lock owner, if any, for the current Fqn.
*
* @param f Fqn to inspect
Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeBasedLockManager.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -262,6 +262,21 @@
return n.getLock().isLocked();
}
+ public boolean isLocked(NodeSPI n, LockType type)
+ {
+ switch (type)
+ {
+ case READ:
+ return n.getLock().isReadLocked();
+ case WRITE:
+ return n.getLock().isWriteLocked();
+ case NONE:
+ default:
+ return false;
+ }
+ }
+
+
public Object getWriteOwner(Fqn f)
{
return getWriteOwner(dataContainer.peek(f));
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationRejoinTest.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -54,8 +54,8 @@
// Cache1 will be used only for recovery.
// Cache2 will perform some updates on the objects and then fail.
- cache1 = new DefaultCacheFactory().createCache(c, false);
- cache2 = new DefaultCacheFactory().createCache(c.clone(), false);
+ cache1 = new DefaultCacheFactory<String, Integer>().createCache(c, false);
+ cache2 = new DefaultCacheFactory<String, Integer>().createCache(c.clone(), false);
}
@AfterTest
@@ -172,7 +172,7 @@
for (int i = 0; i < OBJECT_COUNT / 2; i++)
{
Integer integer = cache.get(Fqn.fromString(String.valueOf(i)), "counter");
- cache.put(Fqn.fromString(String.valueOf(i)), "counter", integer.intValue() + 1);
+ cache.put(Fqn.fromString(String.valueOf(i)), "counter", integer + 1);
}
}
@@ -186,7 +186,7 @@
{
for (int i = 0; i < OBJECT_COUNT; i++)
{
- cache.put(new Fqn<String>(String.valueOf(i)), "counter", new Integer(0));
+ cache.put(Fqn.fromElements(String.valueOf(i)), "counter", 0);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -572,7 +572,7 @@
/**
* Recursively adds GUI nodes starting from fqn
*/
- private void addGuiNode(Fqn<String> fqn)
+ private void addGuiNode(Fqn fqn)
{
Set<Object> children;
@@ -587,7 +587,7 @@
{
for (Object child_name : children)
{
- addGuiNode(new Fqn<String>(fqn, (String) child_name));
+ addGuiNode(Fqn.fromRelativeElements(fqn, (String) child_name));
}
}
}
@@ -598,7 +598,7 @@
Fqn<String> fqnToPath;
if (path.length == 0) fqnToPath = Fqn.ROOT;
List<String> elements = convertMyNodeArrayToStringArray(path);
- fqnToPath = new Fqn<String>(elements);
+ fqnToPath = Fqn.fromList(elements);
if (root.hasChild(fqnToPath))
{
return root.getChild(fqnToPath);
@@ -887,7 +887,7 @@
fqnTextField.setText(Fqn.SEPARATOR);
}
Object[] information = {"Enter fully qualified name",
- fqnTextField};
+ fqnTextField};
final String btnString1 = "OK";
final String btnString2 = "Cancel";
Object[] options = {btnString1, btnString2};
@@ -924,7 +924,7 @@
}
Object[] information = {"Enter fully qualified name",
- fqnTextField};
+ fqnTextField};
final String btnString1 = "OK";
final String btnString2 = "Cancel";
Object[] options = {btnString1, btnString2};
@@ -960,7 +960,7 @@
fqnTextField.setText(Fqn.SEPARATOR);
}
Object[] information = {"Enter fully qualified name",
- fqnTextField};
+ fqnTextField};
final String btnString1 = "OK";
final String btnString2 = "Cancel";
Object[] options = {btnString1, btnString2};
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -1962,7 +1962,7 @@
*/
public void testRemoveAndGetInTransaction() throws Exception
{
- Fqn fqn = new Fqn<String>("/a/b");
+ Fqn fqn = Fqn.fromString("/a/b");
String key = "key";
String value = "value";
Modified: core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/lock/PessimisticLockTest.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -5,6 +5,9 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
+import static org.jboss.cache.lock.LockType.READ;
+import static org.jboss.cache.lock.LockType.WRITE;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
@@ -26,14 +29,16 @@
private Cache<Object, Object> cache;
private TransactionManager tm;
private Fqn<String> fqn = Fqn.fromString("/a/b/c");
+ private LockManager lockManager;
@BeforeMethod(alwaysRun = true)
public void setUp()
{
- cache = new DefaultCacheFactory().createCache(false);
+ cache = new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache.start();
tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ lockManager = TestingUtil.extractLockManager(cache);
}
@AfterMethod(alwaysRun = true)
@@ -58,12 +63,12 @@
cache.put(fqn, "k2", "v2");
NodeSPI<Object, Object> n = (NodeSPI<Object, Object>) cache.getRoot().getChild(fqn);
- assertFalse(n.getLock().isReadLocked());
- assertTrue(n.getLock().isWriteLocked());
- assertTrue(n.getParent().getLock().isReadLocked());
- assertFalse(n.getParent().getLock().isWriteLocked());
- assertTrue(n.getParent().getParent().getLock().isReadLocked());
- assertFalse(n.getParent().getParent().getLock().isWriteLocked());
+ assertFalse(lockManager.isLocked(n, READ));
+ assertTrue(lockManager.isLocked(n, WRITE));
+ assertTrue(lockManager.isLocked(n.getParent(), READ));
+ assertFalse(lockManager.isLocked(n.getParent(), WRITE));
+ assertTrue(lockManager.isLocked(n.getParent().getParent(), READ));
+ assertFalse(lockManager.isLocked(n.getParent().getParent(), WRITE));
tm.commit();
@@ -80,12 +85,12 @@
cache.get(fqn, "k2");
NodeSPI<Object, Object> n = (NodeSPI<Object, Object>) cache.getRoot().getChild(fqn);
- assertTrue(n.getLock().isReadLocked());
- assertFalse(n.getLock().isWriteLocked());
- assertTrue(n.getParent().getLock().isReadLocked());
- assertFalse(n.getParent().getLock().isWriteLocked());
- assertTrue(n.getParent().getParent().getLock().isReadLocked());
- assertFalse(n.getParent().getParent().getLock().isWriteLocked());
+ assertTrue(lockManager.isLocked(n, READ));
+ assertFalse(lockManager.isLocked(n, WRITE));
+ assertTrue(lockManager.isLocked(n.getParent(), READ));
+ assertFalse(lockManager.isLocked(n.getParent(), WRITE));
+ assertTrue(lockManager.isLocked(n.getParent().getParent(), READ));
+ assertFalse(lockManager.isLocked(n.getParent().getParent(), WRITE));
tm.commit();
@@ -102,12 +107,12 @@
cache.remove(fqn, "k2");
NodeSPI<Object, Object> n = (NodeSPI<Object, Object>) cache.getRoot().getChild(fqn);
- assertFalse(n.getLock().isReadLocked());
- assertTrue(n.getLock().isWriteLocked());
- assertTrue(n.getParent().getLock().isReadLocked());
- assertFalse(n.getParent().getLock().isWriteLocked());
- assertTrue(n.getParent().getParent().getLock().isReadLocked());
- assertFalse(n.getParent().getParent().getLock().isWriteLocked());
+ assertFalse(lockManager.isLocked(n, READ));
+ assertTrue(lockManager.isLocked(n, WRITE));
+ assertTrue(lockManager.isLocked(n.getParent(), READ));
+ assertFalse(lockManager.isLocked(n.getParent(), WRITE));
+ assertTrue(lockManager.isLocked(n.getParent().getParent(), READ));
+ assertFalse(lockManager.isLocked(n.getParent().getParent(), WRITE));
tm.commit();
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -19,6 +19,7 @@
import org.jboss.cache.invocation.CacheInvocationDelegate;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.lock.LockManager;
import org.jboss.cache.util.CachePrinter;
import org.jgroups.JChannel;
@@ -58,7 +59,8 @@
field = baseType.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(owner, newValue);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);//just to simplify exception handeling
}
@@ -80,7 +82,8 @@
{
e.printStackTrace();
return null;
- } else
+ }
+ else
{
// try with superclass!!
return extractField(type.getSuperclass(), target, fieldName);
@@ -286,7 +289,8 @@
if (members == null || memberCount > members.size())
{
return false;
- } else if (memberCount < members.size())
+ }
+ else if (memberCount < members.size())
{
// This is an exceptional condition
StringBuffer sb = new StringBuffer("Cache at address ");
@@ -328,7 +332,8 @@
if (members == null || memberCount > members.size())
{
return false;
- } else if (memberCount < members.size())
+ }
+ else if (memberCount < members.size())
{
if (barfIfTooManyMembers)
{
@@ -351,7 +356,8 @@
sb.append(')');
throw new IllegalStateException(sb.toString());
- } else return false;
+ }
+ else return false;
}
return true;
@@ -487,6 +493,11 @@
return (ComponentRegistry) extractField(cache, "componentRegistry");
}
+ public static LockManager extractLockManager(Cache cache)
+ {
+ return extractComponentRegistry(cache).getComponent(LockManager.class);
+ }
+
/**
* For testing only - introspects a cache and extracts the ComponentRegistry
*
@@ -607,7 +618,8 @@
if (c == null)
{
System.out.println(" ** Cache " + count + " is null!");
- } else
+ }
+ else
{
System.out.println(" ** Cache " + count + " is " + c.getLocalAddress());
System.out.println(" " + CachePrinter.printCacheLockingInfo(c));
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -2,9 +2,9 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
+import org.jboss.cache.lock.LockManager;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
@@ -22,8 +22,6 @@
@Test(groups = {"functional", "transaction"})
public class AsyncFullStackInterceptorTest extends AbstractOptimisticTestCase
{
-
-
/**
* @param name
*/
@@ -56,7 +54,6 @@
assertNull(cache.getNode("/one"));
destroyCache(cache);
-
}
public void testSingleInstanceDuplicateCommit() throws Exception
@@ -65,6 +62,7 @@
CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
assertNull(mgr.getTransaction());
mgr.begin();
@@ -97,9 +95,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getNode("/one"));
- assertEquals(false, cache.getRoot().getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode(Fqn.fromString("/one/two"))).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode(Fqn.fromString("/one"))));
+ assertEquals(false, lockManager.isLocked(cache.getNode(Fqn.fromString("/one/two"))));
assertNotNull(cache.getNode("/one/two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -111,6 +109,7 @@
{
groupIncreaser++;
CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -161,14 +160,13 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getNode("/one"));
- assertEquals(false, cache.getRoot().getLock().isLocked());
- assertEquals(false, cache.getNode("/one").getLock().isLocked());
- assertEquals(false, cache.getNode("/one/two").getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
-
}
public void test2InstanceCommit() throws Exception
@@ -176,6 +174,8 @@
groupIncreaser++;
CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
+ LockManager lockManager2 = TestingUtil.extractLockManager(cache2);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -202,9 +202,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getNode("/one"));
- assertEquals(false, cache.getRoot().getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -221,9 +221,9 @@
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
assertNotNull(cache2.getRoot().getChild("one"));
- assertEquals(false, cache2.getRoot().getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one")).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager2.isLocked(cache2.getRoot()));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one")));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one/two")));
assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
@@ -236,6 +236,8 @@
groupIncreaser++;
CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
+ LockManager lockManager2 = TestingUtil.extractLockManager(cache2);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -262,9 +264,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getNode("/one"));
- assertEquals(false, cache.getRoot().getLock().isLocked());
- assertEquals(false, cache.getNode("/one").getLock().isLocked());
- assertEquals(false, cache.getNode("/one/two").getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -281,9 +283,9 @@
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
assertNotNull(cache2.getRoot().getChild("one"));
- assertEquals(false, cache2.getRoot().getLock().isLocked());
- assertEquals(false, cache2.getNode("/one").getLock().isLocked());
- assertEquals(false, cache2.getNode("/one/two").getLock().isLocked());
+ assertEquals(false, lockManager2.isLocked(cache2.getRoot()));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one")));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one/two")));
assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
@@ -306,6 +308,7 @@
groupIncreaser++;
CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -365,9 +368,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getNode("/one"));
- assertEquals(false, cache.getRoot().getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -376,6 +379,7 @@
}
+ @SuppressWarnings("unchecked")
protected CacheSPI<Object, Object> createAsyncReplicatedCache() throws Exception
{
return createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_ASYNC);
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -4,9 +4,10 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
+import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
@@ -66,6 +67,7 @@
TestListener listener = new TestListener();
CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -83,11 +85,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getRoot().getChild("one"));
- assertEquals(false, cache.getRoot().getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -102,6 +102,7 @@
{
groupIncreaser++;
CacheSPI<Object, Object> cache = createCacheWithListener();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -127,11 +128,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getRoot().getChild("one"));
- assertEquals(false, cache.getRoot().getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -172,6 +171,7 @@
{
groupIncreaser++;
CacheSPI<Object, Object> cache = createSyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -206,11 +206,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getRoot().getChild("one"));
- assertEquals(false, cache.getRoot().getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -222,6 +220,7 @@
{
groupIncreaser++;
CacheSPI<Object, Object> cache = createSyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -273,11 +272,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getRoot().getChild("one"));
- assertEquals(false, cache.getRoot().getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -290,6 +287,8 @@
groupIncreaser++;
CacheSPI<Object, Object> cache = createSyncReplicatedCache();
CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
+ LockManager lockManager2 = TestingUtil.extractLockManager(cache2);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -316,11 +315,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getRoot().getChild("one"));
- assertEquals(false, cache.getRoot().getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -334,9 +331,9 @@
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
assertNotNull(cache2.getRoot().getChild("one"));
- assertEquals(false, cache2.getRoot().getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one")).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager2.isLocked(cache2.getRoot()));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one")));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one/two")));
assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
@@ -349,6 +346,8 @@
groupIncreaser++;
CacheSPI<Object, Object> cache = createSyncReplicatedCache();
CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
+ LockManager lockManager2 = TestingUtil.extractLockManager(cache2);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -375,11 +374,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getRoot().getChild("one"));
- assertEquals(false, cache.getRoot().getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -393,9 +390,9 @@
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
assertNotNull(cache2.getRoot().getChild("one"));
- assertEquals(false, cache2.getRoot().getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one")).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager2.isLocked(cache2.getRoot()));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one")));
+ assertEquals(false, lockManager2.isLocked(cache2.getNode("/one/two")));
assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
@@ -415,6 +412,7 @@
groupIncreaser++;
CacheSPI<Object, Object> cache = createSyncReplicatedCache();
CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
+ LockManager lockManager = TestingUtil.extractLockManager(cache);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -475,9 +473,9 @@
assertTrue(cache.exists(Fqn.fromString("/one/two")));
assertNotNull(cache.getRoot().getChild("one"));
- assertEquals(false, cache.getRoot().getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertEquals(false, lockManager.isLocked(cache.getRoot()));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one")));
+ assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
@@ -642,7 +640,7 @@
destroyCache(cache);
}
-
+ @SuppressWarnings("unchecked")
protected CacheSPI<Object, Object> createSyncReplicatedCache() throws Exception
{
return createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_SYNC);
@@ -660,7 +658,7 @@
public void testPuts() throws Exception
{
- CacheSPI cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
Transaction tx;
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
Modified: core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -6,8 +6,9 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.lock.NodeLock;
-import static org.testng.AssertJUnit.assertFalse;
+import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.lock.LockType;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -33,7 +34,7 @@
{
Configuration c = new Configuration();
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- CacheFactory<String, String> instance = new DefaultCacheFactory();
+ CacheFactory<String, String> instance = new DefaultCacheFactory<String, String>();
cache = (CacheSPI<String, String>) instance.createCache(c);
tm = cache.getTransactionManager();
}
@@ -114,27 +115,23 @@
private void assertNotLocked(Fqn fqn)
{
- NodeSPI<String, String> n = cache.peek(fqn, true);
- NodeLock lock = n.getLock();
- assertFalse("node " + fqn + " is locked!", lock.isLocked());
+ assert !TestingUtil.extractLockManager(cache).isLocked(cache.peek(fqn, true)) : "Node " + fqn + " is locked!!";
}
private void assertLocked(Object owner, Fqn fqn, boolean write_locked)
{
+ LockManager lm = TestingUtil.extractLockManager(cache);
NodeSPI<String, String> n = cache.peek(fqn, true);
- if (owner == null)
- owner = Thread.currentThread();
- NodeLock lock = n.getLock();
- assertTrue("node " + fqn + " is not locked", lock.isLocked());
+ if (owner == null) owner = Thread.currentThread();
+ assertTrue("node " + fqn + " is not locked", lm.isLocked(n));
if (write_locked)
{
- assertTrue("node " + fqn + " is not write-locked" + (lock.isReadLocked() ? " but is read-locked instead!" : "!"), lock.isWriteLocked());
+ assertTrue("node " + fqn + " is not write-locked by owner " + owner, lm.ownsLock(fqn, LockType.WRITE, owner));
}
else
{
- assertTrue("node " + fqn + " is not read-locked" + (lock.isWriteLocked() ? " but is write-locked instead!" : "!"), lock.isReadLocked());
+ assertTrue("node " + fqn + " is not read-locked by owner " + owner, lm.ownsLock(fqn, LockType.READ, owner));
}
- assertTrue("owner " + owner + "is not owner for lock " + lock, lock.isOwner(owner));
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -85,8 +85,8 @@
private void initCaches(Configuration.CacheMode caching_mode) throws Exception
{
- cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
- cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache1.getConfiguration().setCacheMode(caching_mode);
cache2.getConfiguration().setCacheMode(caching_mode);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -113,6 +113,9 @@
* to integrate the given cache with a multiplexer.
* <p/>
* param cache a cache that has been configured but not yet created.
+ *
+ * @param cache cache
+ * @throws Exception exception
*/
protected void configureMultiplexer(Cache cache) throws Exception
{
@@ -149,7 +152,7 @@
{
initCaches(Configuration.CacheMode.REPL_SYNC);
cache1.getConfiguration().setSyncCommitPhase(true);
- cache1.getRoot().getLock().releaseAll();
+ TestingUtil.extractLockManager(cache1).unlockAll(cache1.getRoot());
TransactionManager tm = beginTransaction();
cache1.put("/bela/ban", "name", "Bela Ban");
assertEquals(3, cache1.getNumberOfLocksHeld());
@@ -185,9 +188,6 @@
assertTrue("\"age\" must be 38", age == 38);
}
- /**
- * @throws Exception
- */
public void testSimplePut() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
@@ -466,8 +466,6 @@
/**
* Test for JBCACHE-361 -- does marking a tx on the remote side
* rollback-only cause a rollback on the originating side?
- *
- * @throws Exception
*/
public void testSyncReplWithRemoteRollback() throws Exception
{
@@ -586,7 +584,7 @@
* SynchronizationHandlers to register (atHead, atTail), and the OrderedSynchronizationHandler would call the
* SynchronizationHandler in the order in which they are defined.
*
- * @throws Exception
+ * @throws Exception exception
*/
public void testConcurrentPuts() throws Exception
{
@@ -686,8 +684,8 @@
{
Object myMutex = new Object();
- final CacheSPI c1 = (CacheSPI) new DefaultCacheFactory().createCache(false);
- final CacheSPI c2 = (CacheSPI) new DefaultCacheFactory().createCache(false);
+ final CacheSPI<Object, Object> c1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
+ final CacheSPI<Object, Object> c2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
c1.getConfiguration().setClusterName("TempCluster");
c2.getConfiguration().setClusterName("TempCluster");
c1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
@@ -708,7 +706,7 @@
class MyThread extends Thread
{
- Object mutex;
+ final Object mutex;
public MyThread(String name, Object mutex)
{
@@ -747,6 +745,7 @@
}
catch (Exception e)
{
+ // do nothing
}
}
}
@@ -984,12 +983,10 @@
* the cache2.get will get different values.
* Note that we have used sleep to interpose thread execution sequence.
* Although it's not fool proof, it is rather simple and intuitive.
- *
- * @throws Exception
*/
public void testPutTx() throws Exception
{
- TransactionManager tm = null;
+ TransactionManager tm;
try
{
@@ -1032,7 +1029,7 @@
{
public void run()
{
- TransactionManager tm = null;
+ TransactionManager tm;
try
{
@@ -1073,7 +1070,7 @@
{
public void run()
{
- TransactionManager tm = null;
+ TransactionManager tm;
try
{
@@ -1133,7 +1130,7 @@
{
public void run()
{
- TransactionManager tm = null;
+ TransactionManager tm;
try
{
@@ -1164,7 +1161,7 @@
{
public void run()
{
- TransactionManager tm = null;
+ TransactionManager tm;
try
{
@@ -1243,7 +1240,7 @@
CacheSPI<Object, Object> callbackCache;
Object callbackKey;
Exception ex;
- Object mutex = new Object();
+ final Object mutex = new Object();
CallbackListener(CacheSPI<Object, Object> cache, Object callbackKey)
{
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2008-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -16,7 +16,10 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.lock.NodeLock;
+import org.jboss.cache.lock.LockManager;
+import static org.jboss.cache.lock.LockType.READ;
+import static org.jboss.cache.lock.LockType.WRITE;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.util.CachePrinter;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -46,7 +49,8 @@
{
CacheSPI<String, Comparable> cache = null;
UserTransaction tx = null;
- Exception thread_ex;
+ Exception exception;
+ LockManager lockManager;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -63,7 +67,8 @@
cache.create();
cache.start();
- thread_ex = null;
+ exception = null;
+ lockManager = TestingUtil.extractLockManager(cache);
}
@AfterMethod(alwaysRun = true)
@@ -86,6 +91,7 @@
}
catch (Throwable t)
{
+ // do nothing
}
tx = null;
}
@@ -505,24 +511,18 @@
cache.put("/a/b/c", null);
cache.put("/a/b/c", null);
- NodeSPI n = (NodeSPI) cache.getNode("/a");
- NodeLock lock = n.getLock();
- int num = lock.getReaderOwners().size();
- assertEquals(0, num);
+ NodeSPI n = cache.getNode("/a");
+ assert !lockManager.isLocked(n, READ);
// make sure this is write locked.
assertLocked(gtx, "/a", true);
- n = (NodeSPI) cache.getNode("/a/b");
- lock = n.getLock();
- num = lock.getReaderOwners().size();
- assertEquals(0, num);
+ n = cache.getNode("/a/b");
+ assert !lockManager.isLocked(n, READ);
// make sure this is write locked.
assertLocked(gtx, "/a/b", true);
- n = (NodeSPI) cache.getNode("/a/b/c");
- lock = n.getLock();
- num = lock.getReaderOwners().size();
- assertEquals(0, num);
+ n = cache.getNode("/a/b/c");
+ assert !lockManager.isLocked(n, READ);
// make sure this is write locked.
assertLocked(gtx, "/a/b/c", true);
@@ -530,24 +530,19 @@
assertEquals(0, cache.getNumberOfLocksHeld());
}
- private void assertLocked(Object owner, String fqn, boolean write_locked)
+ private void assertLocked(Object owner, String fqn, boolean writeLocked)
{
NodeSPI<String, Comparable> n = cache.peek(Fqn.fromString(fqn), true);
- NodeLock lock = n.getLock();
- if (owner == null)
+ if (owner == null) owner = Thread.currentThread();
+ assertTrue("node " + fqn + " is not locked", lockManager.isLocked(n));
+ if (writeLocked)
{
- owner = Thread.currentThread();
+ assertTrue("node " + fqn + " is not write-locked by owner " + owner, lockManager.ownsLock(Fqn.fromString(fqn), WRITE, owner));
}
- assertTrue("node " + fqn + " is not locked", lock.isLocked());
- if (write_locked)
- {
- assertTrue("node " + fqn + " is not write-locked" + (lock.isReadLocked() ? " but is read-locked instead!" : "!"), lock.isWriteLocked());
- }
else
{
- assertTrue("node " + fqn + " is not read-locked" + (lock.isWriteLocked() ? " but is write-locked instead!" : "!"), lock.isReadLocked());
+ assertTrue("node " + fqn + " is not read-locked by owner " + owner, lockManager.ownsLock(Fqn.fromString(fqn), READ, owner));
}
- assertTrue("owner " + owner + "is not owner", lock.isOwner(owner));
}
public void testConcurrentNodeAccessOnRemovalWithTx() throws Exception
@@ -558,10 +553,8 @@
// this node should now be locked.
TransactionManager tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
Transaction t = tm.suspend();
- Transaction t2;
// start a new tx
tm.begin();
- t2 = tm.getTransaction();
try
{
cache.getNode("/a/b/c");// should fail
@@ -879,7 +872,7 @@
}
catch (Exception e)
{
- thread_ex = e;
+ exception = e;
}
}
}
@@ -908,7 +901,7 @@
}
catch (Exception e)
{
- thread_ex = e;
+ exception = e;
}
}
}
@@ -919,9 +912,9 @@
writer.start();
reader.join();
writer.join();
- if (thread_ex != null)
+ if (exception != null)
{
- throw thread_ex;
+ throw exception;
}
}
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-05-28 09:14:50 UTC (rev 5893)
+++ core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java 2008-05-28 13:31:13 UTC (rev 5894)
@@ -1,6 +1,10 @@
package org.jboss.cache.util.internals;
-import org.jboss.cache.*;
+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.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
@@ -8,7 +12,6 @@
import org.jboss.cache.misc.TestingUtil;
import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import java.util.Timer;
/**
@@ -45,10 +48,11 @@
{
try
{
- Method method = EvictionTimerTask.class.getDeclaredMethod("processRegions", null);
+ Method method = EvictionTimerTask.class.getDeclaredMethod("processRegions", new Class[]{null});
method.setAccessible(true);
method.invoke(timerTask);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
e.printStackTrace();
throw new IllegalStateException(e);
@@ -71,7 +75,8 @@
{
LRUConfiguration configuration = (LRUConfiguration) erConfig.getEvictionPolicyConfig();
ttl = configuration.getTimeToLiveSeconds();
- } else
+ }
+ else
{
throw new IllegalArgumentException("Only LRU being handled for now; please add other implementations here");
}
16 years, 7 months
JBoss Cache SVN: r5893 - in core/trunk/src: test/java/org/jboss/cache/transaction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-28 05:14:50 -0400 (Wed, 28 May 2008)
New Revision: 5893
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java
Log:
Shouldnt just test for a null tx
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-27 20:13:32 UTC (rev 5892)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-28 09:14:50 UTC (rev 5893)
@@ -300,7 +300,7 @@
@Override
public void doAfterCall(InvocationContext ctx, VisitableCommand command)
{
- if (ctx.getTransaction() == null) lockManager.unlock(ctx);
+ if (!ctx.isValidTransaction()) lockManager.unlock(ctx);
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java 2008-05-27 20:13:32 UTC (rev 5892)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java 2008-05-28 09:14:50 UTC (rev 5893)
@@ -28,7 +28,7 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- CacheFactory<String, String> instance = new DefaultCacheFactory();
+ CacheFactory<String, String> instance = new DefaultCacheFactory<String, String>();
cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode("local");
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
16 years, 7 months
JBoss Cache SVN: r5892 - core/trunk/src/main/java/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-27 16:13:32 -0400 (Tue, 27 May 2008)
New Revision: 5892
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
Fixed proper cache locking during cache loading
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-05-27 19:42:22 UTC (rev 5891)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-05-27 20:13:32 UTC (rev 5892)
@@ -431,8 +431,10 @@
{
if (configuration.isNodeLockingOptimistic()) return;
- lockManager.lock(fqn, lockType, ctx.getGlobalTransaction() != null ? ctx.getGlobalTransaction() : Thread.currentThread());
- if (recursive) lockManager.lockAllAndRecord(fqn, lockType, ctx);
+ if (recursive)
+ lockManager.lockAllAndRecord(fqn, lockType, ctx);
+ else
+ lockManager.lockAndRecord(fqn, lockType, ctx);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-27 19:42:22 UTC (rev 5891)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-05-27 20:13:32 UTC (rev 5892)
@@ -190,9 +190,14 @@
lockManager.lockAllAndRecord(dataContainer.peek(command.getTo(), true, false), READ, ctx);
}
Object retValue = invokeNextInterceptor(ctx, command);
- // do a REAL remove here.
- NodeSPI n = dataContainer.peek(command.getFqn(), true, false);
- if (n != null) lockManager.unlockAll(n, Thread.currentThread());
+
+ if (ctx.getTransaction() == null) // not transactional
+ {
+ // do a REAL remove here.
+ NodeSPI n = dataContainer.peek(command.getFqn(), true, false);
+ if (n != null) lockManager.unlockAll(n, Thread.currentThread());
+ }
+
return retValue;
}
16 years, 7 months
JBoss Cache SVN: r5891 - in core/trunk/src: test/java/org/jboss/cache/api and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-05-27 15:42:22 -0400 (Tue, 27 May 2008)
New Revision: 5891
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
Log:
Fixed context scrubbing
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-05-27 19:31:25 UTC (rev 5890)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-05-27 19:42:22 UTC (rev 5891)
@@ -54,7 +54,15 @@
ctx.setGlobalTransaction(gtx);
if (entry == null)
{
- if (gtx != null) ctx.setTransactionEntry(txTable.get(gtx));
+ if (gtx != null)
+ {
+ ctx.setTransactionEntry(txTable.get(gtx));
+ }
+ else if (tx == null)
+ {
+ // then nullify the transaction entry as well
+ ctx.setTransactionEntry(null);
+ }
}
else
{
Modified: core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java 2008-05-27 19:31:25 UTC (rev 5890)
+++ core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java 2008-05-27 19:42:22 UTC (rev 5891)
@@ -4,13 +4,12 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.util.internals.EvictionController;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.internals.EvictionController;
import static org.testng.Assert.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -210,10 +209,13 @@
}
}
- public void testResidencyAndPesimistickLocking() throws Exception
+ public void testResidencyAndPessimisticLocking() throws Exception
{
cache.put(Fqn.fromString("/a/b"), "key", "value");
TransactionManager txManager = cache.getTransactionManager();
+
+ assert cache.getNumberOfLocksHeld() == 0 : "Should have no stale locks!";
+
txManager.begin();
cache.getRoot().getChild(Fqn.fromString("/a/b")).setResident(true);
cache.getRoot().getChild(Fqn.fromString("/a/b")).put("k2", "v2");
@@ -221,6 +223,8 @@
txManager.rollback();
assertTrue(cache.getRoot().getChild(Fqn.fromString("/a/b")).isResident());
+ assert cache.getNumberOfLocksHeld() == 0 : "Should have no stale locks!";
+
txManager.begin();
cache.getRoot().getChild(Fqn.fromString("/a/b")).setResident(false);
cache.getRoot().getChild(Fqn.fromString("/a/b")).put("k2", "v2");
16 years, 7 months