JBoss Cache SVN: r5975 - in pojo/trunk: src/main/java/org/jboss/cache/pojo/impl and 8 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-11 19:23:57 -0400 (Wed, 11 Jun 2008)
New Revision: 5975
Modified:
pojo/trunk/pom.xml
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalTxTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/demo/PojoCacheView.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/PojoCollectionRollbackTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/StateTransferAopTestBase.java
pojo/trunk/src/test/resources/log4j.xml
Log:
Update to core cache 2.2.0.CR3
Modified: pojo/trunk/pom.xml
===================================================================
--- pojo/trunk/pom.xml 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/pom.xml 2008-06-11 23:23:57 UTC (rev 5975)
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<jbosscache-pojo-version>2.2.0-SNAPSHOT</jbosscache-pojo-version>
- <jbosscache-core-version>2.1.0-SNAPSHOT</jbosscache-core-version>
+ <jbosscache-core-version>2.2.0.CR3</jbosscache-core-version>
<jboss.aop.version>2.0.0-SNAPSHOT</jboss.aop.version>
</properties>
<parent>
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -31,12 +31,12 @@
this.cache = cache;
internal_ = internal;
}
-
+
protected Fqn<?> getFqn(Object obj)
{
return null;
}
-
+
protected boolean handles(Class<?> clazz)
{
return false;
@@ -89,8 +89,8 @@
+ " Will just de-reference it.");
}
removeFromReference(fqn, referencingFqn);
-
- return null;
+
+ return null;
}
/**
@@ -133,12 +133,6 @@
private int decrementRefCount(Fqn<?> originalFqn, Fqn<?> referencingFqn) throws CacheException
{
- int count = 0;
- if ((count = internal_.decrementRefCount(originalFqn, referencingFqn)) == (PojoInstance.INITIAL_COUNTER_VALUE + 1))
- {
- internal_.removeIndirectFqn(originalFqn.toString());
- }
-
- return count;
+ return internal_.decrementRefCount(originalFqn, referencingFqn);
}
}
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalConcurrentTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -18,7 +18,7 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.UpgradeException;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.test.Address;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalTxTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalTxTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/LocalTxTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -24,7 +24,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.test.Address;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/NewReplicatedTxTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -26,7 +26,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.test.Address;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedCircularGraphTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -19,7 +19,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.test.Link;
import org.jboss.cache.pojo.test.NodeManager;
import org.jboss.cache.pojo.test.Person;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedObjectGraphTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -7,7 +7,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.test.Address;
import org.jboss.cache.pojo.test.Person;
import org.testng.annotations.AfterMethod;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/ReplicatedTxTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -19,7 +19,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.test.Person;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.testng.annotations.AfterMethod;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/demo/PojoCacheView.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/demo/PojoCacheView.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/demo/PojoCacheView.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -3,7 +3,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.demo.CacheModelDelegate;
-import org.jboss.cache.demo.JBossCacheGUI;
import org.jboss.cache.demo.JBossCacheView;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
@@ -18,12 +17,6 @@
private static Log log = LogFactory.getLog(PojoCacheView.class.getName());
@Override
- protected JBossCacheGUI createCacheGUI(CacheModelDelegate cacheDelegate, boolean useConsole) throws Exception
- {
- return new PojoCacheGUI(cacheDelegate, useConsole);
- }
-
- @Override
protected CacheModelDelegate createCacheDelegate() throws Exception
{
PojoCache pojoCache = PojoCacheFactory.createCache(getConfigurationFile(), false);
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/memory/ReplicatedTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -19,7 +19,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Address;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/optimistic/AbstractOptimisticTestCase.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -30,27 +30,20 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.ReversibleCommand;
+import org.jboss.cache.commands.VersionedDataCommand;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.interceptors.Interceptor;
-import org.jboss.cache.interceptors.InvocationContextInterceptor;
-import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
-import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
-import org.jboss.cache.interceptors.OptimisticReplicationInterceptor;
-import org.jboss.cache.interceptors.TxInterceptor;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.marshall.MethodCall;
-import org.jboss.cache.marshall.MethodCallFactory;
-import org.jboss.cache.marshall.MethodDeclarations;
-import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.optimistic.TestListener;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.transaction.DummyTransactionManager;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.xml.XmlHelper;
import org.testng.annotations.AfterMethod;
import org.w3c.dom.Element;
@@ -312,39 +305,6 @@
}
}
- protected Interceptor getAlteredInterceptorChain(Interceptor newLast, CacheSPI<Object, Object> spi, boolean replicated)
- {
- Interceptor ici = new InvocationContextInterceptor();
- ici.setCache(spi);
-
- Interceptor txInterceptor = new TxInterceptor();
- txInterceptor.setCache(spi);
-
- Interceptor replicationInterceptor = new OptimisticReplicationInterceptor();
- replicationInterceptor.setCache(spi);
-
- Interceptor createInterceptor = new OptimisticCreateIfNotExistsInterceptor();
- createInterceptor.setCache(spi);
-
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(spi);
-
- ici.setNext(txInterceptor);
- if (replicated)
- {
- txInterceptor.setNext(replicationInterceptor);
- replicationInterceptor.setNext(createInterceptor);
- }
- else
- {
- txInterceptor.setNext(createInterceptor);
- }
- createInterceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(newLast);
-
- return ici;
- }
-
public abstract class ExceptionThread extends Thread
{
protected Exception exception;
@@ -360,19 +320,25 @@
}
}
- protected List<MethodCall> injectDataVersion(List<MethodCall> modifications)
+
+
+ protected List<ReversibleCommand> injectDataVersion(List<ReversibleCommand> modifications)
{
List<MethodCall> newList = new LinkedList<MethodCall>();
- for (MethodCall c : modifications)
+ for (ReversibleCommand c : modifications)
{
- Object[] oa = c.getArgs();
- Object[] na = new Object[oa.length + 1];
- System.out.println("*** " + oa.length);
- System.arraycopy(oa, 0, na, 0, oa.length);
- na[oa.length] = new DefaultDataVersion();
- newList.add(MethodCallFactory.create(c.getMethodId(), na));
+ if (c instanceof VersionedDataCommand)
+ {
+ ((VersionedDataCommand) c).setDataVersion(new DefaultDataVersion());
+ }
+// Object[] oa = c.getArgs();
+// Object[] na = new Object[oa.length + 1];
+// System.out.println("*** " + oa.length);
+// System.arraycopy(oa, 0, na, 0, oa.length);
+// na[oa.length] = new DefaultDataVersion();
+// newList.add(MethodCallFactory.create(MethodDeclarations.getVersionedMethodId(c.getMethodId()), na));
}
- return newList;
+ return modifications;
}
}
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalConcurrentTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -17,7 +17,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.lock.UpgradeException;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Address;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/region/LocalTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -22,7 +22,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.proxy.ClassProxy;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.pojo.PojoCache;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/PojoCollectionRollbackTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/PojoCollectionRollbackTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/PojoCollectionRollbackTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -19,6 +19,18 @@
import javax.transaction.TransactionManager;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.ConsoleListener;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeActivated;
+import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.annotation.NodePassivated;
+import org.jboss.cache.notifications.annotation.NodeRemoved;
+import org.jboss.cache.notifications.annotation.NodeVisited;
+import org.jboss.cache.notifications.event.NodeEvent;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.notifications.event.NodeVisitedEvent;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.transaction.DummyTransactionManager;
@@ -63,7 +75,6 @@
{
System.out.println("testNestedMapAndIndexWithModifyRollback");
startTest();
-
// create cached data objects
Map<String, String> obj1 = new HashMap<String, String>();
obj1.put(ID, "1");
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/rollback/ReplicatedTxTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -26,7 +26,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Person;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/ReplicatedTest.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -26,7 +26,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.pojo.PojoCache;
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/StateTransferAopTestBase.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/StateTransferAopTestBase.java 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/statetransfer/StateTransferAopTestBase.java 2008-06-11 23:23:57 UTC (rev 5975)
@@ -37,7 +37,7 @@
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.CacheLoader;
-import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.pojo.test.Address;
Modified: pojo/trunk/src/test/resources/log4j.xml
===================================================================
--- pojo/trunk/src/test/resources/log4j.xml 2008-06-11 14:20:32 UTC (rev 5974)
+++ pojo/trunk/src/test/resources/log4j.xml 2008-06-11 23:23:57 UTC (rev 5975)
@@ -63,7 +63,7 @@
<!-- ================ -->
<category name="org.jboss.cache">
- <priority value="WARN"/>
+ <priority value="DEBUG"/>
</category>
<category name="org.jboss.tm">
15 years, 11 months
JBoss Cache SVN: r5974 - in core/trunk/src: main/java/org/jboss/cache/commands/write and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-06-11 10:20:32 -0400 (Wed, 11 Jun 2008)
New Revision: 5974
Added:
core/trunk/src/test/java/org/jboss/cache/commands/RollbackOnNoOpTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java
core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/InvalidateCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java
Log:
http://jira.jboss.com/jira/browse/JBCACHE-1363
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -137,11 +137,6 @@
}
}
- public NodeSPI peekVersioned(Fqn fqn, DataVersion version)
- {
- return peekVersioned(fqn, version, false);
- }
-
public NodeSPI peekStrict(GlobalTransaction gtx, Fqn fqn, boolean includeInvalid)
{
NodeSPI n = peekVersioned(fqn, null, includeInvalid);
@@ -156,6 +151,11 @@
return n;
}
+ public NodeSPI peekVersioned(Fqn fqn, DataVersion version)
+ {
+ return peekVersioned(fqn, version, false);
+ }
+
public NodeSPI peekVersioned(Fqn fqn, DataVersion version, boolean includeInvalidNodes)
{
if (fqn == null) return null;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/ClearDataCommand.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -75,8 +75,14 @@
public void rollback()
{
if (trace) log.trace("rollback(" + globalTransaction + ", \"" + fqn + "\", " + originalData + ")");
- NodeSPI nodeSPI = dataContainer.peekStrict(globalTransaction, fqn, true);
- nodeSPI.putAllDirect(originalData);
+ NodeSPI nodeSpi = dataContainer.peek(fqn, false, true);
+ if (nodeSpi == null)
+ {
+ if (trace) log.trace("Not rolling back node clearance for node: " + fqn + " as it does not exist in the cache. " +
+ "This might be the result of an NoOp clear operation");
+ return;
+ }
+ nodeSpi.putAllDirect(originalData);
}
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -2,11 +2,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.DataContainerImpl;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.NodeNotExistsException;
-import org.jboss.cache.NodeSPI;
+import org.jboss.cache.*;
import org.jboss.cache.commands.ReversibleCommand;
import org.jboss.cache.commands.Visitor;
import org.jboss.cache.commands.read.AbstractDataCommand;
@@ -37,7 +33,7 @@
{
}
- public void initialize(Notifier notifier, DataContainerImpl dataContainer)
+ public void initialize(Notifier notifier, DataContainer dataContainer)
{
this.notifier = notifier;
this.dataContainer = dataContainer;
@@ -77,7 +73,7 @@
}
- private void moveFqns(NodeSPI node, Fqn newBase)
+ private void adjustFqn(NodeSPI node, Fqn newBase)
{
Fqn newFqn = Fqn.fromRelativeElements(newBase, node.getFqn().getLastElement());
node.setFqn(newFqn);
@@ -88,27 +84,26 @@
return visitor.visitMoveCommand(ctx, this);
}
- private void move(Fqn nodeToMoveFqn, Fqn newParentFqn, boolean skipNotifications, InvocationContext ctx)
+ private void move(Fqn toMoveFqn, Fqn newParentFqn, boolean skipNotifications, InvocationContext ctx)
{
// the actual move algorithm.
- NodeSPI newParent = dataContainer.peek(newParentFqn);
-
+ NodeSPI newParent = dataContainer.peek(newParentFqn, false, false);
if (newParent == null)
{
throw new NodeNotExistsException("New parent node " + newParentFqn + " does not exist when attempting to move node!!");
}
- NodeSPI node = dataContainer.peek(nodeToMoveFqn);
+ NodeSPI node = dataContainer.peek(toMoveFqn, false, false);
if (node == null)
{
- throw new NodeNotExistsException("Node " + nodeToMoveFqn + " does not exist when attempting to move node!!");
+ throw new NodeNotExistsException("Node " + toMoveFqn + " does not exist when attempting to move node!!");
}
if (trace) log.trace("Moving " + fqn + " to sit under " + to);
NodeSPI oldParent = node.getParent();
- Object nodeName = nodeToMoveFqn.getLastElement();
+ Object nodeName = toMoveFqn.getLastElement();
// now that we have the parent and target nodes:
// first correct the pointers at the pruning point
@@ -118,13 +113,13 @@
// notify
if (!skipNotifications)
- notifier.notifyNodeMoved(nodeToMoveFqn, Fqn.fromRelativeElements(newParentFqn, nodeToMoveFqn.getLastElement()), true, ctx);
+ notifier.notifyNodeMoved(toMoveFqn, Fqn.fromRelativeElements(newParentFqn, toMoveFqn.getLastElement()), true, ctx);
// now adjust Fqns of node and all children.
- moveFqns(node, newParent.getFqn());
+ adjustFqn(node, newParent.getFqn());
if (!skipNotifications)
- notifier.notifyNodeMoved(nodeToMoveFqn, Fqn.fromRelativeElements(newParentFqn, nodeToMoveFqn.getLastElement()), false, ctx);
+ notifier.notifyNodeMoved(toMoveFqn, Fqn.fromRelativeElements(newParentFqn, toMoveFqn.getLastElement()), false, ctx);
}
public Fqn getTo()
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -77,7 +77,6 @@
public void rollback()
{
NodeSPI targetNode = dataContainer.peek(fqn, false, true);
- if (targetNode == null) throw new NodeNotExistsException("No such node: " + fqn);
if (oldValue != null)
{
targetNode.putDirect(key, oldValue);
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -47,7 +47,7 @@
public Object perform(InvocationContext ctx)
{
if (trace) log.trace("perform(" + globalTransaction + ", \"" + fqn + ")");
- // Find the node. This will add the temporarily created parent nodes to the TX's node list if globalTransaction != null)
+ // Find the node
targetNode = dataContainer.peekVersioned(fqn, dataVersion, true);
if (targetNode == null)
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -624,7 +624,8 @@
}
catch (Throwable e)
{
- log.warn("Rollback had a problem", e);
+ log.error("Rollback had a problem", e);
+ throw new CacheException("A failure occured durring rollback!", e);
}
finally
{
@@ -968,11 +969,17 @@
switch (status)
{
case Status.STATUS_COMMITTED:
- boolean onePhaseCommit = isOnePhaseCommit();
- if (log.isDebugEnabled()) log.debug("Running commit phase. One phase? " + onePhaseCommit);
- runCommitPhase(ctx, gtx, modifications, onePhaseCommit);
- log.debug("Finished commit phase");
- break;
+ try
+ {
+ boolean onePhaseCommit = isOnePhaseCommit();
+ if (log.isDebugEnabled()) log.debug("Running commit phase. One phase? " + onePhaseCommit);
+ runCommitPhase(ctx, gtx, modifications, onePhaseCommit);
+ log.debug("Finished commit phase");
+ break;
+ } catch (Exception e)
+ {
+ log.trace("Caught exception on After completion", e);
+ }
case Status.STATUS_UNKNOWN:
log.warn("Received JTA STATUS_UNKNOWN in afterCompletion()! XA resources may not be in sync. The app should manually clean up resources at this point.");
case Status.STATUS_MARKED_ROLLBACK:
@@ -986,11 +993,6 @@
throw new IllegalStateException("illegal status: " + status);
}
}
- catch (Exception th)
- {
- log.trace("Caught exception ", th);
-
- }
finally
{
// clean up the tx table
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -24,10 +24,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -73,14 +70,9 @@
storeState(Fqn.ROOT, is);
}
+ @SuppressWarnings("unchecked")
public void storeState(Fqn subtree, ObjectInputStream in) throws Exception
{
-// ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
-// try
-// {
-// // Set the TCCL to any classloader registered for subtree
-// setUnmarshallingClassLoader(subtree);
-
// remove entire existing state
this.remove(subtree);
@@ -103,20 +95,26 @@
}
List nodeData = (List) objectFromStream;
-
- //for (nd = (NodeData) in.readObject(); nd != null && !nd.isMarker(); nd = (NodeData) in.readObject())
- for (Object o : nodeData)
+ for (Object aNodeData : nodeData)
{
- NodeData nd = (NodeData) o;
- if (nd.isMarker()) break;
-
+ NodeData nd = (NodeData) aNodeData;
if (nd.isExceptionMarker())
{
NodeDataExceptionMarker ndem = (NodeDataExceptionMarker) nd;
throw new CacheException("State provider cacheloader at node " + ndem.getCacheNodeIdentity()
+ " threw exception during loadState (see Caused by)", ndem.getCause());
}
+ }
+ storeStateHelper(subtree, nodeData, moveToBuddy);
+ }
+ protected void storeStateHelper(Fqn subtree, List nodeData, boolean moveToBuddy) throws Exception
+ {
+ for (Object aNodeData : nodeData)
+ {
+ NodeData nd = (NodeData) aNodeData;
+ if (nd.isMarker()) break;
+ Fqn fqn;
if (moveToBuddy)
{
fqn = BuddyFqnTransformer.getBackupFqn(subtree, nd.getFqn());
@@ -135,14 +133,6 @@
this.put(fqn, null);// creates a node with null attributes
}
}
-
- // read marker off stack
-// cache.getMarshaller().objectFromObjectStream(in);
-// }
-// finally
-// {
-// Thread.currentThread().setContextClassLoader(currentCL);
-// }
}
public void loadEntireState(ObjectOutputStream os) throws Exception
@@ -243,10 +233,6 @@
/**
* Do a preorder traversal: visit the node first, then the node's children
- *
- * @param fqn Start node
- * @param out
- * @throws Exception
*/
protected void loadStateHelper(Fqn fqn, ObjectOutputStream out) throws Exception
{
@@ -259,9 +245,9 @@
protected void getNodeDataList(Fqn fqn, List<NodeData> list) throws Exception
{
Map<Object, Object> attrs;
- Set<?> children_names;
- String child_name;
- Fqn tmp_fqn;
+ Set<?> childrenNames;
+ String childName;
+ Fqn tmpFqn;
NodeData nd;
// first handle the current node
@@ -278,16 +264,16 @@
list.add(nd);
// then visit the children
- children_names = getChildrenNames(fqn);
- if (children_names == null)
+ childrenNames = getChildrenNames(fqn);
+ if (childrenNames == null)
{
return;
}
- for (Object children_name : children_names)
+ for (Object childrenName : childrenNames)
{
- child_name = (String) children_name;
- tmp_fqn = Fqn.fromRelativeElements(fqn, child_name);
- if (!cache.getInternalFqns().contains(tmp_fqn)) getNodeDataList(tmp_fqn, list);
+ childName = (String) childrenName;
+ tmpFqn = Fqn.fromRelativeElements(fqn, childName);
+ if (!cache.getInternalFqns().contains(tmpFqn)) getNodeDataList(tmpFqn, list);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -4,11 +4,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.marshall.NodeData;
import java.io.InputStream;
+import java.io.ObjectInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -78,6 +80,34 @@
_put(name, attributes);
}
+ @Override
+ protected void storeStateHelper(Fqn subtree, List nodeData, boolean moveToBuddy) throws Exception
+ {
+ for (Object aNodeData : nodeData)
+ {
+ NodeData nd = (NodeData) aNodeData;
+ if (nd.isMarker()) break;
+ Fqn fqn;
+ if (moveToBuddy)
+ {
+ fqn = BuddyFqnTransformer.getBackupFqn(subtree, nd.getFqn());
+ }
+ else
+ {
+ fqn = nd.getFqn();
+ }
+
+ if (nd.getAttributes() != null)
+ {
+ this.put(fqn, nd.getAttributes(), true);// creates a node with 0 or more attributes
+ }
+ else
+ {
+ this.put(fqn, null);// creates a node with null attributes
+ }
+ }
+ }
+
/**
* As per interface's contrect.
* Performance Note: O(1) db calls.
@@ -291,6 +321,12 @@
}
}
+ @Override
+ public void storeState(Fqn subtree, ObjectInputStream in) throws Exception
+ {
+ super.storeState(subtree, in);
+ }
+
public IndividualCacheLoaderConfig getConfig()
{
return config;
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransaction.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -102,6 +102,10 @@
status = Status.STATUS_ROLLEDBACK;
notifyAfterCompletion(Status.STATUS_ROLLEDBACK);
}
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
catch (Throwable t)
{
}
@@ -281,10 +285,15 @@
{
s.afterCompletion(status);
}
- catch (Throwable t)
+ catch (RuntimeException t)
{
log.error("afterCompletion() failed for " + s, t);
+ throw t;
}
+ catch (Exception t)
+ {
+ log.error("afterCompletion() failed for " + s, t);
+ }
}
participants.clear();
}
Added: core/trunk/src/test/java/org/jboss/cache/commands/RollbackOnNoOpTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/RollbackOnNoOpTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/commands/RollbackOnNoOpTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -0,0 +1,78 @@
+package org.jboss.cache.commands;
+
+import org.testng.annotations.Test;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.config.Configuration;
+
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+@Test(groups = "functional")
+public class RollbackOnNoOpTest
+{
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager txMgr;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp()
+ {
+ Configuration cacheConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, false);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(cacheConfig, false);
+ cache.start();
+ txMgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
+ {
+ cache.stop();
+ cache.destroy();
+ }
+
+ public void testRollbackOnRemoveNodeDoesNotFail() throws Exception
+ {
+ txMgr.begin();
+ cache.remove("/blah/blah", "non-exist");
+ txMgr.rollback();
+ }
+
+ public void testRollbackOnClearData() throws Exception
+ {
+ txMgr.begin();
+ cache.clearData("/blah/blah");
+ txMgr.rollback();
+ }
+
+ public void testCreateNodeCommand() throws Exception
+ {
+ cache.put("/blah/blah", "key", "value");
+ txMgr.begin();
+ cache.clearData("/blah/blah");
+ txMgr.rollback();
+ assert cache.get("/blah/blah", "key") != null;
+ }
+
+ public void testRemoveKeyCommand() throws Exception
+ {
+ txMgr.begin();
+ cache.remove("/blah/blah","key");
+ txMgr.rollback();
+ }
+
+ public void testRemoveNodeCommand() throws Exception
+ {
+ cache.put("/blah/blah", "key", "value");
+ txMgr.begin();
+ cache.removeNode("/blah");
+ txMgr.rollback();
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -53,16 +53,6 @@
assert !cache.exists("/a/b");
}
- public void testPutForExternalRead() throws Exception
- {
- assert !cache.exists("/a/b");
- txMgr.begin();
- cache.putForExternalRead(Fqn.fromString("/a/b/c"), "key", "value");
- assert cache.exists("/a/b");
- txMgr.rollback();
- assert !cache.exists("/a/b");
- }
-
public void testPutKeyValueCommand() throws Exception
{
assert !cache.exists("/a/b");
Modified: core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/read/AbstractDataCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -17,13 +17,13 @@
public abstract class AbstractDataCommandTest
{
protected Fqn testFqn = Fqn.fromString("/testfqn");
- protected DataContainer containerMock;
+ protected DataContainer container;
protected InvocationContext ctx;
@BeforeMethod
final public void setUp()
{
- containerMock = createMock(DataContainer.class);
+ container = createMock(DataContainer.class);
ctx = new InvocationContext();
moreSetup();
}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/read/ExistsCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -16,18 +16,18 @@
protected void moreSetup()
{
command = new ExistsCommand(testFqn);
- command.initialize(containerMock);
+ command.initialize(container);
}
public void testPerform()
{
- expect(containerMock.exists(testFqn)).andReturn(Boolean.FALSE);
- replay(containerMock);
+ expect(container.exists(testFqn)).andReturn(Boolean.FALSE);
+ replay(container);
assert Boolean.FALSE == command.perform(null);
- reset(containerMock);
+ reset(container);
- expect(containerMock.exists(testFqn)).andReturn(Boolean.TRUE);
- replay(containerMock);
+ expect(container.exists(testFqn)).andReturn(Boolean.TRUE);
+ replay(container);
assert Boolean.TRUE == command.perform(null);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/read/GetChildrenNamesCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -24,30 +24,30 @@
{
nodes = new MockNodesFixture();
command = new GetChildrenNamesCommand(testFqn);
- command.initialize(containerMock);
+ command.initialize(container);
}
public void testPerformNoChildren()
{
NodeSpiMock node = new NodeSpiMock(testFqn);
- expect(containerMock.peek(testFqn)).andReturn(node);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(node);
+ replay(container);
Set result = (Set) command.perform(null);
assert result.isEmpty() : "empty result expected";
}
public void testPerformInexistingNode()
{
- expect(containerMock.peek(testFqn)).andReturn(null);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(null);
+ replay(container);
Set result = (Set) command.perform(null);
assert result == null : "empty result expected";
}
public void testNodeWithChildren()
{
- expect(containerMock.peek(testFqn)).andReturn(nodes.adfNode);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(nodes.adfNode);
+ replay(container);
Set result = (Set) command.perform(null);
assert result.size() == 2;
assert result.contains("h");
@@ -57,8 +57,8 @@
public void testNodeInvalidChildren()
{
nodes.adfgNode.markAsDeleted(true);
- expect(containerMock.peek(testFqn)).andReturn(nodes.adfNode);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(nodes.adfNode);
+ replay(container);
Set result = (Set) command.perform(null);
assert result.size() == 1;
assert result.contains("h");
Modified: core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/read/GetDataMapCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -20,13 +20,13 @@
protected void moreSetup()
{
command = new GetDataMapCommand(testFqn);
- command.initialize(containerMock);
+ command.initialize(container);
}
public void testForNonexistentNode()
{
- expect(containerMock.peek(testFqn)).andReturn(null);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(null);
+ replay(container);
assert null == command.perform(null);
}
@@ -35,8 +35,8 @@
NodeSpiMock node = new NodeSpiMock(testFqn);
node.putDirect("k1","v1");
node.putDirect("k2","v2");
- expect(containerMock.peek(testFqn)).andReturn(node);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(node);
+ replay(container);
Map result = (Map) command.perform(null);
assert 2 == result.entrySet().size();
assert result.get("k1").equals("v1");
Modified: core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/read/GetKeysCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -5,7 +5,6 @@
import static org.easymock.EasyMock.replay;
import org.jboss.cache.mock.NodeSpiMock;
-import java.util.Map;
import java.util.Set;
/**
@@ -23,13 +22,13 @@
protected void moreSetup()
{
command = new GetKeysCommand(testFqn);
- command.initialize(containerMock);
+ command.initialize(container);
}
public void testForNonexistentNode()
{
- expect(containerMock.peek(testFqn)).andReturn(null);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(null);
+ replay(container);
assert null == command.perform(null);
}
@@ -38,8 +37,8 @@
NodeSpiMock node = new NodeSpiMock(testFqn);
node.putDirect("k1", "v1");
node.putDirect("k2", "v2");
- expect(containerMock.peek(testFqn)).andReturn(node);
- replay(containerMock);
+ expect(container.peek(testFqn)).andReturn(node);
+ replay(container);
Set result = (Set) command.perform(null);
assert 2 == result.size();
assert result.contains("k1");
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/ClearDataCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -46,10 +46,26 @@
//now do a rollback
control.reset();
- expect(container.peekStrict(globalTransaction, fqn, true)).andReturn(nodes.aNode);
+ expect(container.peek(fqn, false, true)).andReturn(nodes.aNode);
control.replay();
command.rollback();
assert nodes.aNode.dataSize() == 1;
assert nodes.aNode.getData().get("key").equals("value");
}
+
+ /**
+ * If clearing data on an inexistent node, the rollback should not fail
+ */
+ public void testNoOpRollback()
+ {
+ expect(container.peek(fqn, false, true)).andReturn(null);
+ control.replay();
+ try
+ {
+ command.rollback();
+ } catch (Exception e)
+ {
+ assert false : "should not fail but expect this scenarion";
+ }
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/CreateNodeCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -3,7 +3,6 @@
import static org.easymock.EasyMock.*;
import org.testng.annotations.Test;
-import org.testng.annotations.BeforeMethod;
import org.jboss.cache.commands.read.AbstractDataCommandTest;
import org.jboss.cache.mock.MockNodesFixture;
@@ -25,7 +24,7 @@
protected void moreSetup()
{
command = new CreateNodeCommand(testFqn);
- command.initialize(containerMock);
+ command.initialize(container);
createdNodes = new ArrayList();
result = new Object[2];
result[0] = this.createdNodes;
@@ -33,8 +32,8 @@
public void testPerformNoNodesCreated()
{
- expect(containerMock.createNodes(testFqn)).andReturn(result);
- replay(containerMock);
+ expect(container.createNodes(testFqn)).andReturn(result);
+ replay(container);
assert null == command.perform(ctx);
assert command.getNewlyCreated().isEmpty();
}
@@ -47,8 +46,8 @@
createdNodes.add(nodes.abcNode);
result[1] = nodes.abcNode;
- expect(containerMock.createNodes(testFqn)).andReturn(result);
- replay(containerMock);
+ expect(container.createNodes(testFqn)).andReturn(result);
+ replay(container);
assert nodes.abcNode == command.perform(ctx);
assert command.getNewlyCreated().size() == 3;
assert command.getNewlyCreated().contains(nodes.a);
@@ -62,14 +61,14 @@
createdNodes.add(nodes.aNode);
createdNodes.add(nodes.abNode);
createdNodes.add(nodes.abcNode);
- expect(containerMock.createNodes(testFqn)).andReturn(result);
- expect(containerMock.removeFromDataStructure(nodes.a, true)).andReturn(Boolean.TRUE);
- expect(containerMock.removeFromDataStructure(nodes.ab, true)).andReturn(Boolean.TRUE);
- expect(containerMock.removeFromDataStructure(nodes.abc, true)).andReturn(Boolean.TRUE);
- replay(containerMock);
+ expect(container.createNodes(testFqn)).andReturn(result);
+ expect(container.removeFromDataStructure(nodes.a, true)).andReturn(Boolean.TRUE);
+ expect(container.removeFromDataStructure(nodes.ab, true)).andReturn(Boolean.TRUE);
+ expect(container.removeFromDataStructure(nodes.abc, true)).andReturn(Boolean.TRUE);
+ replay(container);
command.perform(ctx);
command.rollback();
- verify(containerMock);
+ verify(container);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -30,16 +30,16 @@
{
control = createStrictControl();
notifier = control.createMock(Notifier.class);
- containerMock = control.createMock(DataContainer.class);
+ container = control.createMock(DataContainer.class);
command = new EvictCommand(testFqn);
- command.initialize(notifier, containerMock);
+ command.initialize(notifier, container);
nodes = new MockNodesFixture();
}
public void testResidentNodesEviction()
{
nodes.abNode.setResident(true);
- expect(containerMock.peek(testFqn, false,false)).andReturn(nodes.abNode);
+ expect(container.peek(testFqn, false,false)).andReturn(nodes.abNode);
control.replay();
assert Boolean.TRUE == command.perform(ctx);
control.verify();
@@ -47,9 +47,9 @@
public void testSimpleEviction()
{
- expect(containerMock.peek(testFqn, false,false)).andReturn(nodes.abNode);
+ expect(container.peek(testFqn, false,false)).andReturn(nodes.abNode);
notifier.notifyNodeEvicted(testFqn, true, ctx);
- expect(containerMock.evict(testFqn)).andReturn(true);
+ expect(container.evict(testFqn)).andReturn(true);
notifier.notifyNodeEvicted(testFqn, false, ctx);
control.replay();
assert Boolean.TRUE == command.perform(ctx);
@@ -62,18 +62,18 @@
nodesToEvict.add(nodes.a);
nodesToEvict.add(nodes.ab);
command.setRecursive(true);
- expect(containerMock.peek(testFqn, false,false)).andReturn(nodes.aNode);
+ expect(container.peek(testFqn, false,false)).andReturn(nodes.aNode);
- expect(containerMock.getNodesForEviction(testFqn, true)).andReturn(nodesToEvict);
+ expect(container.getNodesForEviction(testFqn, true)).andReturn(nodesToEvict);
control.checkOrder(false);
//evict a
notifier.notifyNodeEvicted(nodes.a, true, ctx);
- expect(containerMock.evict(nodes.a)).andReturn(true);
+ expect(container.evict(nodes.a)).andReturn(true);
notifier.notifyNodeEvicted(nodes.a, false, ctx);
//evict b
notifier.notifyNodeEvicted(nodes.ab, true, ctx);
- expect(containerMock.evict(nodes.ab)).andReturn(true);
+ expect(container.evict(nodes.ab)).andReturn(true);
notifier.notifyNodeEvicted(nodes.ab, false, ctx);
control.replay();
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/InvalidateCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/InvalidateCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/InvalidateCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -33,12 +33,12 @@
{
control = createStrictControl();
notifier = control.createMock(Notifier.class);
- containerMock = control.createMock(DataContainer.class);
+ container = control.createMock(DataContainer.class);
tmMock = control.createMock(TransactionManager.class);
spiMock = control.createMock(CacheSPI.class);
command = new InvalidateCommand(testFqn);
- command.initialize(spiMock, containerMock, notifier);
+ command.initialize(spiMock, container, notifier);
nodes = new MockNodesFixture();
}
@@ -54,7 +54,7 @@
{
expect(spiMock.getNode(testFqn)).andReturn(nodes.adfNode);
notifier.notifyNodeEvicted(testFqn, true, ctx);
- expect(containerMock.evict(testFqn)).andReturn(Boolean.TRUE);
+ expect(container.evict(testFqn)).andReturn(Boolean.TRUE);
notifier.notifyNodeEvicted(testFqn, false, ctx);
control.replay();
assert null == command.perform(ctx);
@@ -70,7 +70,7 @@
nodes.adfgNode.put("key","value");
expect(spiMock.getNode(Fqn.ROOT)).andReturn(nodes.root);
notifier.notifyNodeEvicted(Fqn.ROOT, true, ctx);
- expect(containerMock.evict(Fqn.ROOT)).andReturn(Boolean.TRUE);
+ expect(container.evict(Fqn.ROOT)).andReturn(Boolean.TRUE);
notifier.notifyNodeEvicted(Fqn.ROOT, false, ctx);
control.replay();
assert null == command.perform(ctx);
Added: core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/MoveCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -0,0 +1,72 @@
+package org.jboss.cache.commands.write;
+
+import static org.easymock.EasyMock.*;
+import org.jboss.cache.notifications.Notifier;
+import org.jboss.cache.mock.MockNodesFixture;
+import org.jboss.cache.commands.read.AbstractDataCommandTest;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeNotExistsException;
+import org.easymock.IMocksControl;
+import static org.easymock.EasyMock.createStrictControl;
+import org.testng.annotations.Test;
+
+/**
+ * Tester class for {@link org.jboss.cache.commands.write.MoveCommand}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+@Test(groups = "unit")
+public class MoveCommandTest extends AbstractDataCommandTest
+{
+ MoveCommand command;
+ Notifier notifier;
+ IMocksControl control;
+ MockNodesFixture nodes;
+
+ Fqn source = Fqn.fromString("/source");
+ Fqn destination = Fqn.fromString("/destination");
+
+ protected void moreSetup()
+ {
+ control = createStrictControl();
+ notifier = control.createMock(Notifier.class);
+ container = control.createMock(DataContainer.class);
+ command = new MoveCommand(source, destination);
+ command.initialize(notifier, container);
+ nodes = new MockNodesFixture();
+ }
+
+ public void testFailsOnMissingSource()
+ {
+ control.checkOrder(false);
+ expect(container.peek(source, false, false)).andReturn(null);
+ expect(container.peek(destination, false, false)).andReturn(nodes.adfgNode);
+ control.replay();
+ try
+ {
+ command.perform(ctx);
+ assert false : "should have thrown an exception as the source is null";
+ } catch (NodeNotExistsException e)
+ {
+ //expected
+ }
+ }
+
+ public void testFailsOnMissingDestination()
+ {
+ control.checkOrder(false);
+ expect(container.peek(source, false, false)).andReturn(nodes.adfgNode);
+ expect(container.peek(destination, false, false)).andReturn(null);
+ control.replay();
+ try
+ {
+ command.perform(ctx);
+ assert false : "should have thrown an exception as the source is null";
+ } catch (NodeNotExistsException e)
+ {
+ //expected
+ }
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/OptimisticInvalidateCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -38,7 +38,7 @@
{
control = createStrictControl();
notifier = control.createMock(Notifier.class);
- containerMock = control.createMock(DataContainer.class);
+ container = control.createMock(DataContainer.class);
tmMock = control.createMock(TransactionManager.class);
spiMock = control.createMock(CacheSPI.class);
nodes = new MockNodesFixture();
@@ -46,7 +46,7 @@
command = new OptimisticInvalidateCommand(testFqn);
dataVersion = new DefaultDataVersion(10);
command.setDataVersion(dataVersion);
- command.initialize(spiMock, containerMock, notifier);
+ command.initialize(spiMock, container, notifier);
command.initialize(tmMock);
}
@@ -55,10 +55,10 @@
nodes.adfNode.put("key", "value");
nodes.adfNode.setDataLoaded(true);
expect(spiMock.getNode(testFqn)).andReturn(nodes.adfNode);
- expect(containerMock.peekVersioned(testFqn, dataVersion)).andReturn(nodes.adfNode);
+ expect(container.peekVersioned(testFqn, dataVersion)).andReturn(nodes.adfNode);
notifier.notifyNodeEvicted(testFqn, true, ctx);
notifier.notifyNodeEvicted(testFqn, false, ctx);
- expect(containerMock.peek(testFqn, false, true)).andReturn(nodes.adfNode);
+ expect(container.peek(testFqn, false, true)).andReturn(nodes.adfNode);
control.replay();
assert null == command.perform(ctx);
@@ -75,7 +75,7 @@
nodes.adfNode.put("key", "value");
nodes.adfNode.setDataLoaded(true);
expect(spiMock.getNode(testFqn)).andReturn(nodes.adfNode);
- expect(containerMock.peekVersioned(testFqn, dataVersion)).andThrow(new RuntimeException());
+ expect(container.peekVersioned(testFqn, dataVersion)).andThrow(new RuntimeException());
control.replay();
try
@@ -98,11 +98,11 @@
{
nodes.adfNode.setValid(false, true);
expect(spiMock.getNode(testFqn)).andReturn(null);
- expect(containerMock.peek(testFqn, false, true)).andReturn(nodes.adfNode);
- expect(containerMock.peekVersioned(testFqn, dataVersion)).andReturn(nodes.adfNode);
+ expect(container.peek(testFqn, false, true)).andReturn(nodes.adfNode);
+ expect(container.peekVersioned(testFqn, dataVersion)).andReturn(nodes.adfNode);
notifier.notifyNodeEvicted(testFqn, true, ctx);
notifier.notifyNodeEvicted(testFqn, false, ctx);
- expect(containerMock.peek(testFqn, false, true)).andReturn(nodes.adfNode);
+ expect(container.peek(testFqn, false, true)).andReturn(nodes.adfNode);
control.replay();
assert null == command.perform(ctx);
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java 2008-06-11 13:22:08 UTC (rev 5973)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/RemoveKeyCommandTest.java 2008-06-11 14:20:32 UTC (rev 5974)
@@ -85,4 +85,21 @@
assert "newValue".equals(nodes.adfgNode.getData().get(key));
control.verify();
}
+
+ /**
+ * On an no-op scenario the user will try to remove a key on an unexisting node.
+ * When rollback is being called, the node might not exist in the cache and we should know how to handle that.
+ */
+ public void testRollbackOnNoOp()
+ {
+ expect(container.peek(fqn, false, true)).andReturn(null);
+ control.replay();
+ try
+ {
+ command.rollback();
+ } catch (Exception ex)
+ {
+ assert false : "No exception should be thrown here.";
+ }
+ }
}
15 years, 11 months
JBoss Cache SVN: r5973 - core/trunk/src/test/java/org/jboss/cache/commands.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-06-11 09:22:08 -0400 (Wed, 11 Jun 2008)
New Revision: 5973
Added:
core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java
Log:
added unit test to reproduce error
Added: core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/commands/StructuralNodesOnRollbackTest.java 2008-06-11 13:22:08 UTC (rev 5973)
@@ -0,0 +1,75 @@
+package org.jboss.cache.commands;
+
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.config.Configuration;
+
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+
+/**
+ * Test to check that structural nodes are being removed on rollback: http://jira.jboss.com/jira/browse/JBCACHE-1365.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+@Test(groups = "functional")
+public class StructuralNodesOnRollbackTest
+{
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager txMgr;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp()
+ {
+ Configuration cacheConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, false);
+ cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(cacheConfig, false);
+ cache.start();
+ txMgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
+ {
+ cache.stop();
+ cache.destroy();
+ }
+
+ public void testPutDataMap() throws Exception
+ {
+ HashMap map = new HashMap();
+ map.put("k","v");
+
+ assert !cache.exists("/a/b");
+ txMgr.begin();
+ cache.put("/a/b/c", map);
+ assert cache.exists("/a/b");
+ txMgr.rollback();
+ assert !cache.exists("/a/b");
+ }
+
+ public void testPutForExternalRead() throws Exception
+ {
+ assert !cache.exists("/a/b");
+ txMgr.begin();
+ cache.putForExternalRead(Fqn.fromString("/a/b/c"), "key", "value");
+ assert cache.exists("/a/b");
+ txMgr.rollback();
+ assert !cache.exists("/a/b");
+ }
+
+ public void testPutKeyValueCommand() throws Exception
+ {
+ assert !cache.exists("/a/b");
+ txMgr.begin();
+ cache.put("/a/b/c", "key", "value");
+ assert cache.exists("/a/b");
+ txMgr.rollback();
+ assert !cache.exists("/a/b");
+ }
+}
15 years, 11 months
JBoss Cache SVN: r5972 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-11 06:02:18 -0400 (Wed, 11 Jun 2008)
New Revision: 5972
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
Log:
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-11 09:30:03 UTC (rev 5971)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-11 10:02:18 UTC (rev 5972)
@@ -12,7 +12,7 @@
*/
public interface SearchableCache extends Cache
{
- public QueryResult find(Query luceneQuery);
+ public QueryResult createQuery(Query luceneQuery);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-11 09:30:03 UTC (rev 5971)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-11 10:02:18 UTC (rev 5972)
@@ -34,12 +34,12 @@
this.cache = cache;
}
- public QueryResult find(Query luceneQuery)
+ public QueryResult createQuery(Query luceneQuery)
{
return new QueryResultImpl(luceneQuery, cache);
}
- public QueryResult find(Query luceneQuery, Class... classes)
+ public QueryResult createQuery(Query luceneQuery, Class... classes)
{
return new QueryResultImpl(luceneQuery, cache, classes);
15 years, 11 months
JBoss Cache SVN: r5971 - core/branches/1.4.X/tests/functional/org/jboss/cache/transaction.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-06-11 05:30:03 -0400 (Wed, 11 Jun 2008)
New Revision: 5971
Added:
core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java
Log:
added a new unit test
Added: core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java
===================================================================
--- core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java (rev 0)
+++ core/branches/1.4.X/tests/functional/org/jboss/cache/transaction/IsolationLevelReadUncommitedTest.java 2008-06-11 09:30:03 UTC (rev 5971)
@@ -0,0 +1,102 @@
+package org.jboss.cache.transaction;
+
+import EDU.oswego.cs.dl.util.concurrent.Latch;
+
+import javax.transaction.Transaction;
+import javax.transaction.SystemException;
+import javax.transaction.NotSupportedException;
+
+import org.jboss.cache.TreeCache;
+import org.jboss.cache.DummyTransactionManagerLookup;
+import org.jboss.cache.lock.IsolationLevel;
+import junit.framework.TestCase;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class IsolationLevelReadUncommitedTest extends TestCase {
+
+ private TreeCache cache = null;
+
+ private Transaction startTransaction() throws SystemException, NotSupportedException
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr.begin();
+ return mgr.getTransaction();
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ cache = new TreeCache();
+ cache.setCacheMode(TreeCache.LOCAL);
+ cache.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED);
+ cache.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.setLockAcquisitionTimeout(1000);
+ cache.startService();
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ cache.stopService();
+ cache.destroyService();
+ cache = null;
+ }
+
+ /**
+ * Tests following scenario:
+ * tx1 starts and create /a/b/c
+ * tx2 starts and adds a key value under /a/b
+ * tx2 commits
+ * tx1 rollabcks
+ *
+ * the key/value added bu tx should be in the cache still, and should not be affected by tx1 rollback.
+ */
+ public void testInterlacedTx() throws Exception
+ {
+ Transaction tx = startTransaction();
+ cache.put("/a/b/c", "key", "value");
+ System.out.println("Tx1 just added /a/b/c");
+ System.out.println(cache.printLockInfo());
+ Latch latch = new Latch();
+ TxThread txThread = new TxThread(cache, latch);
+ txThread.start();
+ latch.acquire();
+ tx.rollback();
+ System.out.println("Tx1 just rolled back");
+ System.out.println(cache.printLockInfo());
+
+ assertNotNull(cache.get("/a/b"));
+ assertNotNull(cache.get("/a/b", "newKey"));
+ }
+
+ private class TxThread extends Thread
+ {
+ TreeCache cache;
+ Latch latch;
+
+ private TxThread(TreeCache cache, Latch latch) {
+ this.cache = cache;
+ this.latch = latch;
+ }
+
+ public void run() {
+ try {
+ Transaction tx = startTransaction();
+ cache.put("/a/b","newKey","newValue");
+ System.out.println("Tx2 just updated /a/b");
+ System.out.println(cache.printLockInfo());
+ tx.commit();
+ System.out.println("Tx2 commited");
+ latch.release();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException();
+ }
+ }
+ }
+}
\ No newline at end of file
15 years, 11 months
JBoss Cache SVN: r5970 - pojo/trunk/src/main/java/org/jboss/cache/pojo/util.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-10 22:00:37 -0400 (Tue, 10 Jun 2008)
New Revision: 5970
Modified:
pojo/trunk/src/main/java/org/jboss/cache/pojo/util/ConcurrentReferenceHashMap.java
Log:
Merge 5969
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/util/ConcurrentReferenceHashMap.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/util/ConcurrentReferenceHashMap.java 2008-06-11 01:45:40 UTC (rev 5969)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/util/ConcurrentReferenceHashMap.java 2008-06-11 02:00:37 UTC (rev 5970)
@@ -262,6 +262,7 @@
static interface KeyReference {
int keyHash();
+ Object keyRef();
}
/**
@@ -269,13 +270,17 @@
*/
static final class WeakKeyReference<K> extends WeakReference<K> implements KeyReference {
final int hash;
- WeakKeyReference(K key, int hash, ReferenceQueue<K> refQueue) {
+ WeakKeyReference(K key, int hash, ReferenceQueue<Object> refQueue) {
super(key, refQueue);
this.hash = hash;
}
public final int keyHash() {
return hash;
}
+
+ public final Object keyRef() {
+ return this;
+ }
}
/**
@@ -283,15 +288,54 @@
*/
static final class SoftKeyReference<K> extends SoftReference<K> implements KeyReference {
final int hash;
- SoftKeyReference(K key, int hash, ReferenceQueue<K> refQueue) {
+ SoftKeyReference(K key, int hash, ReferenceQueue<Object> refQueue) {
super(key, refQueue);
this.hash = hash;
}
public final int keyHash() {
return hash;
}
+
+ public final Object keyRef() {
+ return this;
+ }
}
+ static final class WeakValueReference<V> extends WeakReference<V> implements KeyReference {
+ final Object keyRef;
+ final int hash;
+ WeakValueReference(V value, Object keyRef, int hash, ReferenceQueue<Object> refQueue) {
+ super(value, refQueue);
+ this.keyRef = keyRef;
+ this.hash = hash;
+ }
+
+ public final int keyHash() {
+ return hash;
+ }
+
+ public final Object keyRef() {
+ return keyRef;
+ }
+ }
+
+ static final class SoftValueReference<V> extends SoftReference<V> implements KeyReference {
+ final Object keyRef;
+ final int hash;
+ SoftValueReference(V value, Object keyRef, int hash, ReferenceQueue<Object> refQueue) {
+ super(value, refQueue);
+ this.keyRef = keyRef;
+ this.hash = hash;
+ }
+ public final int keyHash() {
+ return hash;
+ }
+
+ public final Object keyRef() {
+ return keyRef;
+ }
+ }
+
/**
* ConcurrentReferenceHashMap list entry. Note that this is never exported
* out as a user-visible Map.Entry.
@@ -312,15 +356,15 @@
HashEntry(K key, int hash, HashEntry<K,V> next, V value,
ReferenceType keyType, ReferenceType valueType,
- ReferenceQueue<K> refQueue) {
- this.keyRef = newKeyReference(key, keyType, hash, refQueue);
+ ReferenceQueue<Object> refQueue) {
this.hash = hash;
this.next = next;
- this.valueRef = newValueReference(value, valueType);
+ this.keyRef = newKeyReference(key, keyType, refQueue);
+ this.valueRef = newValueReference(value, valueType, refQueue);
}
- final Object newKeyReference(K key, ReferenceType keyType, int hash,
- ReferenceQueue<K> refQueue) {
+ final Object newKeyReference(K key, ReferenceType keyType,
+ ReferenceQueue<Object> refQueue) {
if (keyType == ReferenceType.WEAK)
return new WeakKeyReference<K>(key, hash, refQueue);
if (keyType == ReferenceType.SOFT)
@@ -329,11 +373,12 @@
return key;
}
- final Object newValueReference(V value, ReferenceType valueType) {
+ final Object newValueReference(V value, ReferenceType valueType,
+ ReferenceQueue<Object> refQueue) {
if (valueType == ReferenceType.WEAK)
- return new WeakReference<V>(value);
+ return new WeakValueReference<V>(value, keyRef, hash, refQueue);
if (valueType == ReferenceType.SOFT)
- return new SoftReference<V>(value);
+ return new SoftValueReference<V>(value, keyRef, hash, refQueue);
return value;
}
@@ -358,8 +403,8 @@
return (V) value;
}
- final void setValue(V value, ReferenceType valueType) {
- this.valueRef = newValueReference(value, valueType);
+ final void setValue(V value, ReferenceType valueType, ReferenceQueue<Object> refQueue) {
+ this.valueRef = newValueReference(value, valueType, refQueue);
}
@SuppressWarnings("unchecked")
@@ -452,7 +497,7 @@
* The collected weak-key reference queue for this segment.
* This should be (re)initialized whenever table is assigned,
*/
- transient volatile ReferenceQueue<K> refQueue;
+ transient volatile ReferenceQueue<Object> refQueue;
final ReferenceType keyType;
@@ -485,7 +530,7 @@
void setTable(HashEntry<K,V>[] newTable) {
threshold = (int)(newTable.length * loadFactor);
table = newTable;
- refQueue = new ReferenceQueue<K>();
+ refQueue = new ReferenceQueue<Object>();
}
/**
@@ -581,7 +626,7 @@
boolean replaced = false;
if (e != null && oldValue.equals(e.value())) {
replaced = true;
- e.setValue(newValue, valueType);
+ e.setValue(newValue, valueType, refQueue);
}
return replaced;
} finally {
@@ -600,7 +645,7 @@
V oldValue = null;
if (e != null) {
oldValue = e.value();
- e.setValue(newValue, valueType);
+ e.setValue(newValue, valueType, refQueue);
}
return oldValue;
} finally {
@@ -631,7 +676,7 @@
if (e != null) {
oldValue = e.value();
if (!onlyIfAbsent)
- e.setValue(value, valueType);
+ e.setValue(value, valueType, refQueue);
}
else {
oldValue = null;
@@ -718,19 +763,19 @@
/**
* Remove; match on key only if value null, else match both.
*/
- V remove(Object key, int hash, Object value, boolean weakRemove) {
+ V remove(Object key, int hash, Object value, boolean refRemove) {
lock();
try {
- if (!weakRemove)
+ if (!refRemove)
removeStale();
int c = count - 1;
HashEntry<K,V>[] tab = table;
int index = hash & (tab.length - 1);
HashEntry<K,V> first = tab[index];
HashEntry<K,V> e = first;
- // a weak remove operation compares the WeakReference instance
- while (e != null && (!weakRemove || key != e.keyRef)
- && (e.hash != hash || !keyEq(key, e.key())))
+ // a ref remove operation compares the Reference instance
+ while (e != null && key != e.keyRef
+ && (refRemove || hash != e.hash || !keyEq(key, e.key())))
e = e.next;
V oldValue = null;
@@ -763,12 +808,9 @@
}
final void removeStale() {
- if (keyType == ReferenceType.STRONG)
- return;
-
KeyReference ref;
while ((ref = (KeyReference) refQueue.poll()) != null) {
- remove(ref, ref.keyHash(), null, true);
+ remove(ref.keyRef(), ref.keyHash(), null, true);
}
}
@@ -781,7 +823,7 @@
tab[i] = null;
++modCount;
// replace the reference queue to avoid unnecessary stale cleanups
- refQueue = new ReferenceQueue<K>();
+ refQueue = new ReferenceQueue<Object>();
count = 0; // write-volatile
} finally {
unlock();
15 years, 11 months
JBoss Cache SVN: r5969 - experimental/jsr166/src/jsr166y.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-10 21:45:40 -0400 (Tue, 10 Jun 2008)
New Revision: 5969
Modified:
experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java
Log:
collected values should also clear the entry
Modified: experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java
===================================================================
--- experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java 2008-06-10 20:01:37 UTC (rev 5968)
+++ experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMap.java 2008-06-11 01:45:40 UTC (rev 5969)
@@ -31,11 +31,11 @@
* An advanced hash table supporting configurable garbage collection semantics
* of keys and values, optional referential-equality, full concurrency of
* retrievals, and adjustable expected concurrency for updates.
- *
+ *
* This table is designed around specific advanced use-cases. If there is any
* doubt whether this table is for you, you most likely should be using
* {@link java.util.concurrent.ConcurrentHashMap} instead.
- *
+ *
* This table supports strong, weak, and soft keys and values. By default keys
* are weak, and values are strong. Such a configuration offers similar behavior
* to {@link java.util.WeakHashMap}, entries of this table are periodically
@@ -48,13 +48,13 @@
* <tt>isEmpty</tt> might return a value greater than the observed number of
* entries. In order to support a high level of concurrency, stale entries are
* only reclaimed during blocking (usually mutating) operations.
- *
+ *
* Enabling soft keys allows entries in this table to remain until their space
* is absolutely needed by the garbage collector. This is unlike weak keys which
* can be reclaimed as soon as they are no longer referenced by a normal strong
* reference. The primary use case for soft keys is a cache, which ideally
* occupies memory that is not in use for as long as possible.
- *
+ *
* By default, values are held using a normal strong reference. This provides
* the commonly desired guarantee that a value will always have at least the
* same life-span as it's key. For this reason, care should be taken to ensure
@@ -62,11 +62,11 @@
* preventing reclamation. If this is unavoidable, then it is recommended to use
* the same reference type in use for the key. However, it should be noted that
* non-strong values may disappear before their corresponding key.
- *
+ *
* While this table does allow the use of both strong keys and values, it is
* recommended to use {@link java.util.concurrent.ConcurrentHashMap} for such a
* configuration, since it is optimized for that case.
- *
+ *
* Just like {@link java.util.concurrent.ConcurrentHashMap}, this class obeys
* the same functional specification as {@link java.util.Hashtable}, and
* includes versions of methods corresponding to each method of
@@ -76,7 +76,7 @@
* prevents all access. This class is fully interoperable with
* <tt>Hashtable</tt> in programs that rely on its thread safety but not on
* its synchronization details.
- *
+ *
* <p>
* Retrieval operations (including <tt>get</tt>) generally do not block, so
* may overlap with update operations (including <tt>put</tt> and
@@ -89,7 +89,7 @@
* iterator/enumeration. They do <em>not</em> throw
* {@link ConcurrentModificationException}. However, iterators are designed to
* be used by only one thread at a time.
- *
+ *
* <p>
* The allowed concurrency among update operations is guided by the optional
* <tt>concurrencyLevel</tt> constructor argument (default <tt>16</tt>),
@@ -106,19 +106,19 @@
* any other kind of hash table is a relatively slow operation, so, when
* possible, it is a good idea to provide estimates of expected table sizes in
* constructors.
- *
+ *
* <p>
* This class and its views and iterators implement all of the <em>optional</em>
* methods of the {@link Map} and {@link Iterator} interfaces.
- *
+ *
* <p>
* Like {@link Hashtable} but unlike {@link HashMap}, this class does
* <em>not</em> allow <tt>null</tt> to be used as a key or value.
- *
+ *
* <p>
* This class is a member of the <a href="{@docRoot}/../technotes/guides/collections/index.html">
* Java Collections Framework</a>.
- *
+ *
* @author Doug Lea
* @author Jason T. Greene
* @param <K> the type of keys maintained by this map
@@ -139,27 +139,27 @@
*/
public static enum ReferenceType {
/** Indicates a normal Java strong reference should be used */
- STRONG,
+ STRONG,
/** Indicates a {@link WeakReference} should be used */
WEAK,
/** Indicates a {@link SoftReference} should be used */
SOFT
};
-
-
+
+
public static enum Option {
- /** Indicates that referential-equality (== instead of .equals()) should
+ /** Indicates that referential-equality (== instead of .equals()) should
* be used when locating keys. This offers similar behavior to {@link IdentityHashMap} */
IDENTITY_COMPARISONS
};
-
+
/* ---------------- Constants -------------- */
static final ReferenceType DEFAULT_KEY_TYPE = ReferenceType.WEAK;
-
+
static final ReferenceType DEFAULT_VALUE_TYPE = ReferenceType.STRONG;
-
-
+
+
/**
* The default initial capacity for this table,
* used when not otherwise specified in a constructor.
@@ -217,7 +217,7 @@
* The segments, each of which is a specialized hash table
*/
final Segment<K,V>[] segments;
-
+
boolean identityComparisons;
transient Set<K> keySet;
@@ -252,46 +252,90 @@
final Segment<K,V> segmentFor(int hash) {
return segments[(hash >>> segmentShift) & segmentMask];
}
-
+
private int hashOf(Object key) {
- return hash(identityComparisons ?
+ return hash(identityComparisons ?
System.identityHashCode(key) : key.hashCode());
}
-
+
/* ---------------- Inner Classes -------------- */
-
+
static interface KeyReference {
int keyHash();
+ Object keyRef();
}
-
+
/**
* A weak-key reference which stores the key hash needed for reclamation.
*/
static final class WeakKeyReference<K> extends WeakReference<K> implements KeyReference {
final int hash;
- WeakKeyReference(K key, int hash, ReferenceQueue<K> refQueue) {
+ WeakKeyReference(K key, int hash, ReferenceQueue<Object> refQueue) {
super(key, refQueue);
this.hash = hash;
}
public final int keyHash() {
return hash;
}
+
+ public final Object keyRef() {
+ return this;
+ }
}
-
+
/**
* A soft-key reference which stores the key hash needed for reclamation.
*/
static final class SoftKeyReference<K> extends SoftReference<K> implements KeyReference {
final int hash;
- SoftKeyReference(K key, int hash, ReferenceQueue<K> refQueue) {
+ SoftKeyReference(K key, int hash, ReferenceQueue<Object> refQueue) {
super(key, refQueue);
this.hash = hash;
}
public final int keyHash() {
return hash;
}
+
+ public final Object keyRef() {
+ return this;
+ }
}
-
+
+ static final class WeakValueReference<V> extends WeakReference<V> implements KeyReference {
+ final Object keyRef;
+ final int hash;
+ WeakValueReference(V value, Object keyRef, int hash, ReferenceQueue<Object> refQueue) {
+ super(value, refQueue);
+ this.keyRef = keyRef;
+ this.hash = hash;
+ }
+
+ public final int keyHash() {
+ return hash;
+ }
+
+ public final Object keyRef() {
+ return keyRef;
+ }
+ }
+
+ static final class SoftValueReference<V> extends SoftReference<V> implements KeyReference {
+ final Object keyRef;
+ final int hash;
+ SoftValueReference(V value, Object keyRef, int hash, ReferenceQueue<Object> refQueue) {
+ super(value, refQueue);
+ this.keyRef = keyRef;
+ this.hash = hash;
+ }
+ public final int keyHash() {
+ return hash;
+ }
+
+ public final Object keyRef() {
+ return keyRef;
+ }
+ }
+
/**
* ConcurrentReferenceHashMap list entry. Note that this is never exported
* out as a user-visible Map.Entry.
@@ -310,56 +354,57 @@
volatile Object valueRef;
final HashEntry<K,V> next;
- HashEntry(K key, int hash, HashEntry<K,V> next, V value,
- ReferenceType keyType, ReferenceType valueType,
- ReferenceQueue<K> refQueue) {
- this.keyRef = newKeyReference(key, keyType, hash, refQueue);
+ HashEntry(K key, int hash, HashEntry<K,V> next, V value,
+ ReferenceType keyType, ReferenceType valueType,
+ ReferenceQueue<Object> refQueue) {
this.hash = hash;
this.next = next;
- this.valueRef = newValueReference(value, valueType);
+ this.keyRef = newKeyReference(key, keyType, refQueue);
+ this.valueRef = newValueReference(value, valueType, refQueue);
}
-
- final Object newKeyReference(K key, ReferenceType keyType, int hash,
- ReferenceQueue<K> refQueue) {
+
+ final Object newKeyReference(K key, ReferenceType keyType,
+ ReferenceQueue<Object> refQueue) {
if (keyType == ReferenceType.WEAK)
return new WeakKeyReference<K>(key, hash, refQueue);
if (keyType == ReferenceType.SOFT)
return new SoftKeyReference<K>(key, hash, refQueue);
-
+
return key;
}
-
- final Object newValueReference(V value, ReferenceType valueType) {
+
+ final Object newValueReference(V value, ReferenceType valueType,
+ ReferenceQueue<Object> refQueue) {
if (valueType == ReferenceType.WEAK)
- return new WeakReference<V>(value);
+ return new WeakValueReference<V>(value, keyRef, hash, refQueue);
if (valueType == ReferenceType.SOFT)
- return new SoftReference<V>(value);
-
+ return new SoftValueReference<V>(value, keyRef, hash, refQueue);
+
return value;
}
-
+
@SuppressWarnings("unchecked")
final K key() {
if (keyRef instanceof Reference)
return ((Reference<K>)keyRef).get();
-
+
return (K) keyRef;
}
-
+
final V value() {
return dereferenceValue(valueRef);
}
-
+
@SuppressWarnings("unchecked")
final V dereferenceValue(Object value) {
if (value instanceof Reference)
return ((Reference<V>)value).get();
-
+
return (V) value;
}
-
- final void setValue(V value, ReferenceType valueType) {
- this.valueRef = newValueReference(value, valueType);
+
+ final void setValue(V value, ReferenceType valueType, ReferenceQueue<Object> refQueue) {
+ this.valueRef = newValueReference(value, valueType, refQueue);
}
@SuppressWarnings("unchecked")
@@ -449,18 +494,18 @@
final float loadFactor;
/**
- * The collected weak-key reference queue for this segment.
+ * The collected weak-key reference queue for this segment.
* This should be (re)initialized whenever table is assigned,
*/
- transient volatile ReferenceQueue<K> refQueue;
-
+ transient volatile ReferenceQueue<Object> refQueue;
+
final ReferenceType keyType;
-
+
final ReferenceType valueType;
-
+
final boolean identityComparisons;
-
- Segment(int initialCapacity, float lf, ReferenceType keyType,
+
+ Segment(int initialCapacity, float lf, ReferenceType keyType,
ReferenceType valueType, boolean identityComparisons) {
loadFactor = lf;
this.keyType = keyType;
@@ -473,11 +518,11 @@
static final <K,V> Segment<K,V>[] newArray(int i) {
return new Segment[i];
}
-
+
private boolean keyEq(Object src, Object dest) {
return identityComparisons ? src == dest : src.equals(dest);
}
-
+
/**
* Sets table to new HashEntry array.
* Call only while holding lock or in constructor.
@@ -485,7 +530,7 @@
void setTable(HashEntry<K,V>[] newTable) {
threshold = (int)(newTable.length * loadFactor);
table = newTable;
- refQueue = new ReferenceQueue<K>();
+ refQueue = new ReferenceQueue<Object>();
}
/**
@@ -495,7 +540,7 @@
HashEntry<K,V>[] tab = table;
return tab[hash & (tab.length - 1)];
}
-
+
HashEntry<K,V> newHashEntry(K key, int hash, HashEntry<K, V> next, V value) {
return new HashEntry<K,V>(key, hash, next, value, keyType, valueType, refQueue);
}
@@ -526,8 +571,8 @@
if (e.hash == hash && keyEq(key, e.key())) {
Object opaque = e.valueRef;
if (opaque != null)
- return e.dereferenceValue(opaque);
-
+ return e.dereferenceValue(opaque);
+
return readValueUnderLock(e); // recheck
}
e = e.next;
@@ -556,12 +601,12 @@
for (HashEntry<K,V> e = tab[i]; e != null; e = e.next) {
Object opaque = e.valueRef;
V v;
-
- if (opaque == null)
+
+ if (opaque == null)
v = readValueUnderLock(e); // recheck
- else
+ else
v = e.dereferenceValue(opaque);
-
+
if (value.equals(v))
return true;
}
@@ -581,7 +626,7 @@
boolean replaced = false;
if (e != null && oldValue.equals(e.value())) {
replaced = true;
- e.setValue(newValue, valueType);
+ e.setValue(newValue, valueType, refQueue);
}
return replaced;
} finally {
@@ -600,7 +645,7 @@
V oldValue = null;
if (e != null) {
oldValue = e.value();
- e.setValue(newValue, valueType);
+ e.setValue(newValue, valueType, refQueue);
}
return oldValue;
} finally {
@@ -617,9 +662,9 @@
if (c++ > threshold) {// ensure capacity
int reduced = rehash();
if (reduced > 0) // adjust from possible weak cleanups
- count = (c -= reduced) - 1; // write-volatile
+ count = (c -= reduced) - 1; // write-volatile
}
-
+
HashEntry<K,V>[] tab = table;
int index = hash & (tab.length - 1);
HashEntry<K,V> first = tab[index];
@@ -631,7 +676,7 @@
if (e != null) {
oldValue = e.value();
if (!onlyIfAbsent)
- e.setValue(value, valueType);
+ e.setValue(value, valueType, refQueue);
}
else {
oldValue = null;
@@ -718,19 +763,19 @@
/**
* Remove; match on key only if value null, else match both.
*/
- V remove(Object key, int hash, Object value, boolean weakRemove) {
+ V remove(Object key, int hash, Object value, boolean refRemove) {
lock();
try {
- if (!weakRemove)
+ if (!refRemove)
removeStale();
int c = count - 1;
HashEntry<K,V>[] tab = table;
int index = hash & (tab.length - 1);
HashEntry<K,V> first = tab[index];
HashEntry<K,V> e = first;
- // a weak remove operation compares the WeakReference instance
- while (e != null && (!weakRemove || key != e.keyRef)
- && (e.hash != hash || !keyEq(key, e.key())))
+ // a ref remove operation compares the Reference instance
+ while (e != null && key != e.keyRef
+ && (refRemove || hash != e.hash || !keyEq(key, e.key())))
e = e.next;
V oldValue = null;
@@ -749,7 +794,7 @@
c--;
continue;
}
-
+
newFirst = newHashEntry(pKey, p.hash, newFirst, p.value());
}
tab[index] = newFirst;
@@ -761,14 +806,11 @@
unlock();
}
}
-
+
final void removeStale() {
- if (keyType == ReferenceType.STRONG)
- return;
-
KeyReference ref;
while ((ref = (KeyReference) refQueue.poll()) != null) {
- remove(ref, ref.keyHash(), null, true);
+ remove(ref.keyRef(), ref.keyHash(), null, true);
}
}
@@ -781,7 +823,7 @@
tab[i] = null;
++modCount;
// replace the reference queue to avoid unnecessary stale cleanups
- refQueue = new ReferenceQueue<K>();
+ refQueue = new ReferenceQueue<Object>();
count = 0; // write-volatile
} finally {
unlock();
@@ -797,7 +839,7 @@
/**
* Creates a new, empty map with the specified initial
* capacity, reference types, load factor and concurrency level.
- *
+ *
* Behavioral changing options such as {@link Option#IDENTITY_COMPARISONS}
* can also be specified.
*
@@ -817,7 +859,7 @@
* nonpositive.
*/
public ConcurrentReferenceHashMap(int initialCapacity,
- float loadFactor, int concurrencyLevel,
+ float loadFactor, int concurrencyLevel,
ReferenceType keyType, ReferenceType valueType,
EnumSet<Option> options) {
if (!(loadFactor > 0) || initialCapacity < 0 || concurrencyLevel <= 0)
@@ -845,11 +887,11 @@
int cap = 1;
while (cap < c)
cap <<= 1;
-
+
identityComparisons = options != null && options.contains(Option.IDENTITY_COMPARISONS);
for (int i = 0; i < this.segments.length; ++i)
- this.segments[i] = new Segment<K,V>(cap, loadFactor,
+ this.segments[i] = new Segment<K,V>(cap, loadFactor,
keyType, valueType, identityComparisons);
}
@@ -871,10 +913,10 @@
*/
public ConcurrentReferenceHashMap(int initialCapacity,
float loadFactor, int concurrencyLevel) {
- this(initialCapacity, loadFactor, concurrencyLevel,
+ this(initialCapacity, loadFactor, concurrencyLevel,
DEFAULT_KEY_TYPE, DEFAULT_VALUE_TYPE, null);
}
-
+
/**
* Creates a new, empty map with the specified initial capacity
* and load factor and with the default reference types (weak keys,
@@ -896,7 +938,7 @@
/**
- * Creates a new, empty map with the specified initial capacity,
+ * Creates a new, empty map with the specified initial capacity,
* reference types and with default load factor (0.75) and concurrencyLevel (16).
*
* @param initialCapacity the initial capacity. The implementation
@@ -906,12 +948,12 @@
* @throws IllegalArgumentException if the initial capacity of
* elements is negative.
*/
- public ConcurrentReferenceHashMap(int initialCapacity,
+ public ConcurrentReferenceHashMap(int initialCapacity,
ReferenceType keyType, ReferenceType valueType) {
- this(initialCapacity, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL,
+ this(initialCapacity, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL,
keyType, valueType, null);
}
-
+
/**
* Creates a new, empty map with the specified initial capacity,
* and with default reference types (weak keys, strong values),
@@ -1251,15 +1293,15 @@
for (int i = 0; i < segments.length; ++i)
segments[i].clear();
}
-
+
/**
* Removes any stale entries whose keys have been finalized. Use of this
* method is normally not necessary since stale entries are automatically
* removed lazily, when blocking operations are required. However, there
* are some cases where this operation should be performed eagerly, such
- * as cleaning up old references to a ClassLoader in a multi-classloader
+ * as cleaning up old references to a ClassLoader in a multi-classloader
* environment.
- *
+ *
* Note: this method will acquire locks, one at a time, across all segments
* of this table, so if it is to be used, it should be used sparingly.
*/
@@ -1267,8 +1309,8 @@
for (int i = 0; i < segments.length; ++i)
segments[i].removeStale();
}
-
+
/**
* Returns a {@link Set} view of the keys contained in this map.
* The set is backed by the map, so changes to the map are
@@ -1393,13 +1435,13 @@
}
}
- public boolean hasNext() {
+ public boolean hasNext() {
while (nextEntry != null) {
- if (nextEntry.key() != null)
+ if (nextEntry.key() != null)
return true;
advance();
}
-
+
return false;
}
@@ -1407,12 +1449,12 @@
do {
if (nextEntry == null)
throw new NoSuchElementException();
-
+
lastReturned = nextEntry;
currentKey = lastReturned.key();
advance();
} while (currentKey == null); // Skip GC'd keys
-
+
return lastReturned;
}
@@ -1627,7 +1669,7 @@
K key = e.key();
if (key == null) // Skip GC'd keys
continue;
-
+
s.writeObject(key);
s.writeObject(e.value());
}
Modified: experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java
===================================================================
--- experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java 2008-06-10 20:01:37 UTC (rev 5968)
+++ experimental/jsr166/src/jsr166y/ConcurrentReferenceHashMapGCTestCase.java 2008-06-11 01:45:40 UTC (rev 5969)
@@ -13,51 +13,54 @@
public void testWeakCleanup() throws Exception {
basicCleanup(false);
}
-
+
public void testWeakIterators() throws Exception {
iterators(false);
}
-
+
public void testSoftCleanup() throws Exception {
basicCleanup(true);
}
-
+
public void testSoftIterators() throws Exception {
iterators(true);
}
-
+
public void testSoftValues() throws Exception {
values(true);
}
-
+
public void testWeakValues() throws Exception {
values(false);
}
-
+
private void values(boolean soft) throws Exception {
- ConcurrentReferenceHashMap<String, Integer> map =
+ ConcurrentReferenceHashMap<String, Integer> map =
new ConcurrentReferenceHashMap<String, Integer>(16,
- ReferenceType.STRONG,
+ ReferenceType.STRONG,
soft ? ReferenceType.SOFT : ReferenceType.WEAK);
-
+
Integer i = 5;
map.put("five", i);
map.put("one", new Integer(1));
assertEquals(2, map.size());
assertEquals(i, map.get("five"));
assertEquals(new Integer(1), map.get("one"));
-
+
gc(soft);
- assertEquals(2, map.size());
+
+ Thread.sleep(500);
+ map.purgeStaleEntries();
+ assertEquals(1, map.size());
assertEquals(i, map.get("five"));
- assertTrue(map.containsKey("one"));
+ assertFalse(map.containsKey("one"));
assertNull(map.get("one"));
}
-
+
private void basicCleanup(boolean soft) throws Exception {
- ConcurrentReferenceHashMap<BinClump, Integer> map =
- new ConcurrentReferenceHashMap<BinClump, Integer>(16,
- soft ? ReferenceType.SOFT : ReferenceType.WEAK,
+ ConcurrentReferenceHashMap<BinClump, Integer> map =
+ new ConcurrentReferenceHashMap<BinClump, Integer>(16,
+ soft ? ReferenceType.SOFT : ReferenceType.WEAK,
ReferenceType.STRONG);
BinClump[] hold = new BinClump[100];
generateClumps(map, hold, 10000);
@@ -72,9 +75,9 @@
}
private void iterators(boolean soft) throws Exception {
- ConcurrentReferenceHashMap<BinClump, Integer> map =
- new ConcurrentReferenceHashMap<BinClump, Integer>(16,
- soft ? ReferenceType.SOFT : ReferenceType.WEAK,
+ ConcurrentReferenceHashMap<BinClump, Integer> map =
+ new ConcurrentReferenceHashMap<BinClump, Integer>(16,
+ soft ? ReferenceType.SOFT : ReferenceType.WEAK,
ReferenceType.STRONG);
BinClump[] hold = new BinClump[100];
generateClumps(map, hold, 10000);
@@ -141,7 +144,7 @@
private void gc(boolean soft) {
System.gc();
-
+
if (soft) {
int chunkSize = (int) Math.min(
Runtime.getRuntime().maxMemory() / 16, Integer.MAX_VALUE);
@@ -151,7 +154,7 @@
list.add(new long[chunkSize]);
} catch (OutOfMemoryError e) {
}
-
+
System.gc();
}
}
15 years, 11 months
JBoss Cache SVN: r5968 - core/trunk/src/main/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-06-10 16:01:37 -0400 (Tue, 10 Jun 2008)
New Revision: 5968
Modified:
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
Log:
[JBCACHE-1362] Avoid IndexOutOfBoundsException
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-06-10 16:06:42 UTC (rev 5967)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-06-10 20:01:37 UTC (rev 5968)
@@ -292,7 +292,7 @@
@SuppressWarnings("unchecked")
public static boolean isDeadBackupFqn(Fqn name)
{
- if (name == null) return false;
+ if (name == null || name.size() < 2) return false;
Object elem1 = name.get(1);
if (elem1 instanceof String)
{
15 years, 11 months
JBoss Cache SVN: r5967 - in core/tags/2.2.0.CR3: src/main/java/org/jboss/cache and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-10 12:06:42 -0400 (Tue, 10 Jun 2008)
New Revision: 5967
Modified:
core/tags/2.2.0.CR3/pom.xml
core/tags/2.2.0.CR3/src/main/java/org/jboss/cache/Version.java
Log:
Updated Version
Modified: core/tags/2.2.0.CR3/pom.xml
===================================================================
--- core/tags/2.2.0.CR3/pom.xml 2008-06-10 16:04:34 UTC (rev 5966)
+++ core/tags/2.2.0.CR3/pom.xml 2008-06-10 16:06:42 UTC (rev 5967)
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
- <jbosscache-core-version>2.2.0-SNAPSHOT</jbosscache-core-version>
+ <jbosscache-core-version>2.2.0.CR3</jbosscache-core-version>
<!-- By default only run tests in the "unit" group -->
<defaultTestGroup>unit</defaultTestGroup>
<!-- By default only generate Javadocs when we install the module. -->
@@ -410,7 +410,7 @@
<activeByDefault>false</activeByDefault>
</activation>
<properties>
- <jbosscache-core-version>2.2.0-SNAPSHOT-JBossAS</jbosscache-core-version>
+ <jbosscache-core-version>2.2.0.CR3-JBossAS</jbosscache-core-version>
</properties>
<dependencies>
<dependency>
Modified: core/tags/2.2.0.CR3/src/main/java/org/jboss/cache/Version.java
===================================================================
--- core/tags/2.2.0.CR3/src/main/java/org/jboss/cache/Version.java 2008-06-10 16:04:34 UTC (rev 5966)
+++ core/tags/2.2.0.CR3/src/main/java/org/jboss/cache/Version.java 2008-06-10 16:06:42 UTC (rev 5967)
@@ -11,10 +11,10 @@
@Immutable
public class Version
{
- public static final String version = "2.2.0-SNAPSHOT";
+ public static final String version = "2.2.0.CR3";
public static final String codename = "Poblano";
//public static final String cvs = "$Id: Version.java 4592 2007-10-10 16:44:36Z manik.surtani(a)jboss.com $";
- static final byte[] version_id = {'0', '2', '2', '0', 'S'};
+ static final byte[] version_id = {'0', '2', '2', '0', 'C', '3'};
private static final int MAJOR_SHIFT = 11;
private static final int MINOR_SHIFT = 6;
15 years, 11 months
JBoss Cache SVN: r5966 - core/tags.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-10 12:04:34 -0400 (Tue, 10 Jun 2008)
New Revision: 5966
Added:
core/tags/2.2.0.CR3/
Log:
Copied: core/tags/2.2.0.CR3 (from rev 5965, core/trunk)
15 years, 11 months