[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/optimistic ...
Manik Surtani
msurtani at jboss.com
Sat Nov 11 14:55:18 EST 2006
User: msurtani
Date: 06/11/11 14:55:18
Modified: tests/functional/org/jboss/cache/optimistic
TxInterceptorTest.java CacheTest.java
OptimisticReplicationInterceptorTest.java
AbstractOptimisticTestCase.java
Added: tests/functional/org/jboss/cache/optimistic
VersioningOnReadTest.java
Log:
JBCACHE-842 and JBCACHE-843
Revision Changes Path
1.17 +12 -12 JBossCache/tests/functional/org/jboss/cache/optimistic/TxInterceptorTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TxInterceptorTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/TxInterceptorTest.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- TxInterceptorTest.java 7 Sep 2006 16:59:05 -0000 1.16
+++ TxInterceptorTest.java 11 Nov 2006 19:55:18 -0000 1.17
@@ -347,11 +347,11 @@
}
});
//hack the method call to make it have the remote gtx
- MethodCall meth = (MethodCall) entry.getModifications().get(0);
+ MethodCall meth = entry.getModifications().get(0);
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
@@ -443,11 +443,11 @@
}
});
//hack the method call to make it have the remote gtx
- MethodCall meth = (MethodCall) entry.getModifications().get(0);
+ MethodCall meth = entry.getModifications().get(0);
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
@@ -564,11 +564,11 @@
}
});
//hack the method call to make it have the remote gtx
- MethodCall meth = (MethodCall) entry.getModifications().get(0);
+ MethodCall meth = entry.getModifications().get(0);
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
@@ -689,11 +689,11 @@
}
});
//hack the method call to make it have the remote gtx
- MethodCall meth = (MethodCall) entry.getModifications().get(0);
+ MethodCall meth = entry.getModifications().get(0);
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
@@ -824,11 +824,11 @@
});
// hack the method call to make it have the remote gtx
- MethodCall meth = (MethodCall) entry.getModifications().get(0);
+ MethodCall meth = entry.getModifications().get(0);
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
@@ -946,11 +946,11 @@
});
// hack the method call to make it have the remote gtx
- MethodCall meth = (MethodCall) entry.getModifications().get(0);
+ MethodCall meth = entry.getModifications().get(0);
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
1.25 +2 -2 JBossCache/tests/functional/org/jboss/cache/optimistic/CacheTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/CacheTest.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- CacheTest.java 7 Sep 2006 16:59:05 -0000 1.24
+++ CacheTest.java 11 Nov 2006 19:55:18 -0000 1.25
@@ -237,11 +237,11 @@
});
//hack the method call to make it have the remote gtx
- MethodCall meth = (MethodCall) entry.getModifications().get(0);
+ MethodCall meth = entry.getModifications().get(0);
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE});
try
{
cache._replicate(prepareMethod);
1.18 +3 -3 JBossCache/tests/functional/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: OptimisticReplicationInterceptorTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- OptimisticReplicationInterceptorTest.java 7 Sep 2006 16:59:05 -0000 1.17
+++ OptimisticReplicationInterceptorTest.java 11 Nov 2006 19:55:18 -0000 1.18
@@ -150,7 +150,7 @@
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), false);
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
try
{
cache._replicate(prepareMethod);
@@ -219,7 +219,7 @@
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), false);
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
try
{
cache._replicate(prepareMethod);
@@ -423,7 +423,7 @@
meth.getArgs()[0] = remoteGtx;
//call our remote method
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, entry.getModifications(), null, remoteGtx.getAddress(), false);
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
try
{
cache._replicate(prepareMethod);
1.42 +23 -1 JBossCache/tests/functional/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbstractOptimisticTestCase.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- AbstractOptimisticTestCase.java 25 Oct 2006 04:50:20 -0000 1.41
+++ AbstractOptimisticTestCase.java 11 Nov 2006 19:55:18 -0000 1.42
@@ -18,6 +18,9 @@
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.transaction.DummyTransactionManager;
import org.jboss.cache.xml.XmlHelper;
@@ -26,6 +29,9 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Random;
/**
@@ -345,5 +351,21 @@
}
}
+ protected List injectDataVersion(List modifications)
+ {
+ List newList = new ArrayList();
+ Iterator mi = modifications.iterator();
+ while (mi.hasNext())
+ {
+ MethodCall c = (MethodCall) mi.next();
+ Object[] oa = c.getArgs();
+ Object[] na = new Object[oa.length + 1];
+ System.out.println("*** " + oa.length);
+ for (int i = 0; i < oa.length; i++) na[i] = oa[i];
+ na[oa.length] = new DefaultDataVersion();
+ newList.add(MethodCallFactory.create(MethodDeclarations.getVersionedMethod(c.getMethodId()), na));
+ }
+ return newList;
+ }
}
1.2 +153 -0 JBossCache/tests/functional/org/jboss/cache/optimistic/VersioningOnReadTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: VersioningOnReadTest.java
===================================================================
RCS file: VersioningOnReadTest.java
diff -N VersioningOnReadTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ VersioningOnReadTest.java 11 Nov 2006 19:55:18 -0000 1.2
@@ -0,0 +1,153 @@
+package org.jboss.cache.optimistic;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.TreeCache;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ */
+public class VersioningOnReadTest extends AbstractOptimisticTestCase
+{
+ TreeCache cache;
+ Fqn fqn = Fqn.fromString("/a");
+ TransactionManager tm;
+
+ public VersioningOnReadTest(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ cache = createCache();
+ tm = cache.getTransactionManager();
+ }
+
+ protected void tearDown()
+ {
+ super.tearDown();
+ destroyCache(cache);
+ }
+
+ public void testUpdateOnWrite() throws Exception
+ {
+ cache.put(fqn, "k", "v");
+
+ assertEquals("v", cache.get(fqn, "k"));
+
+ // now start a tx to mod the node
+ tm.begin();
+ cache.put(fqn, "k", "v2");
+
+ // suspend the tx
+ Transaction tx = tm.suspend();
+
+ // now modify the node
+ cache.put(fqn, "k", "v3");
+
+ // resume the tx
+ tm.resume(tx);
+
+ try
+ {
+ tm.commit();
+ fail("Should have failed with a data version mismatch");
+ }
+ catch (Exception e)
+ {
+ // do nothing
+ }
+ }
+
+ public void testUpdateOnRemove() throws Exception
+ {
+ cache.put(fqn, "k", "v");
+
+ assertEquals("v", cache.get(fqn, "k"));
+
+ // now start a tx to mod the node
+ tm.begin();
+ cache.remove(fqn, "k");
+
+ // suspend the tx
+ Transaction tx = tm.suspend();
+
+ // now modify the node
+ cache.put(fqn, "k", "v3");
+
+ // resume the tx
+ tm.resume(tx);
+
+ try
+ {
+ tm.commit();
+ fail("Should have failed with a data version mismatch");
+ }
+ catch (Exception e)
+ {
+ // do nothing
+ }
+ }
+
+ public void testUpdateOnRemoveNode() throws Exception
+ {
+ cache.put(fqn, "k", "v");
+
+ assertEquals("v", cache.get(fqn, "k"));
+
+ // now start a tx to mod the node
+ tm.begin();
+ cache.remove(fqn);
+
+ // suspend the tx
+ Transaction tx = tm.suspend();
+
+ // now modify the node
+ cache.put(fqn, "k", "v3");
+
+ // resume the tx
+ tm.resume(tx);
+
+ try
+ {
+ tm.commit();
+ fail("Should have failed with a data version mismatch");
+ }
+ catch (Exception e)
+ {
+ // do nothing
+ }
+ }
+
+
+ public void testUpdateOnRead() throws Exception
+ {
+ cache.put(fqn, "k", "v");
+
+ assertEquals("v", cache.get(fqn, "k"));
+
+ // now start a tx to mod the node
+ tm.begin();
+ cache.get(fqn, "k");
+
+ // suspend the tx
+ Transaction tx = tm.suspend();
+
+ // now modify the node
+ cache.put(fqn, "k", "v3");
+
+ // resume the tx
+ tm.resume(tx);
+
+ // now put some other stuff elsewhere
+ cache.put(Fqn.fromString("/b"), "k", "v");
+
+ // this should succeed since there is no contention on writing to /a
+ tm.commit();
+ }
+
+}
More information about the jboss-cvs-commits
mailing list