[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/optimistic ...
Manik Surtani
manik at jboss.org
Wed Mar 7 13:00:51 EST 2007
User: msurtani
Date: 07/03/07 13:00:51
Modified: tests/functional/org/jboss/cache/optimistic
AbstractOptimisticTestCase.java CacheTest.java
NodeInterceptorRemoveNodeTest.java
Added: tests/functional/org/jboss/cache/optimistic
LockParentVersionTest.java ParentVersionTest.java
Log:
JBCACHE-961 - more sophisticated merging of child maps in workspace nodes.
Revision Changes Path
1.47 +2 -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.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- AbstractOptimisticTestCase.java 7 Feb 2007 22:06:50 -0000 1.46
+++ AbstractOptimisticTestCase.java 7 Mar 2007 18:00:51 -0000 1.47
@@ -4,6 +4,7 @@
package org.jboss.cache.optimistic;
import junit.framework.TestCase;
+import org.jboss.cache.Cache;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheListener;
import org.jboss.cache.CacheSPI;
@@ -156,7 +157,7 @@
return cache;
}
- protected void destroyCache(CacheImpl c)
+ protected void destroyCache(Cache c)
{
c.stop();
c.destroy();
1.30 +27 -28 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.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- CacheTest.java 7 Feb 2007 22:06:50 -0000 1.29
+++ CacheTest.java 7 Mar 2007 18:00:51 -0000 1.30
@@ -335,34 +335,33 @@
}
-
- public void testRemotePessCacheBroadcast() throws Exception
- {
- destroyCache(c);
-
- CacheImpl cache = createPessimisticCache();
- CacheImpl cache2 = createPessimisticCache();
-
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
-
- //start local transaction
- mgr.begin();
- Transaction tx = mgr.getTransaction();
-
- //this sets
- cache.getCurrentTransaction(tx);
-
- SamplePojo pojo = new SamplePojo(21, "test");
-
- cache.put("/one/two", "key1", pojo);
-
-
- mgr.commit();
-
- destroyCache(cache);
- destroyCache(cache2);
-
- }
+// public void testRemotePessCacheBroadcast() throws Exception
+// {
+// destroyCache(c);
+//
+// CacheImpl cache = createPessimisticCache();
+// CacheImpl cache2 = createPessimisticCache();
+//
+// DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+//
+// //start local transaction
+// mgr.begin();
+// Transaction tx = mgr.getTransaction();
+//
+// //this sets
+// cache.getCurrentTransaction(tx);
+//
+// SamplePojo pojo = new SamplePojo(21, "test");
+//
+// cache.put("/one/two", "key1", pojo);
+//
+//
+// mgr.commit();
+//
+// destroyCache(cache);
+// destroyCache(cache2);
+//
+// }
public void testConcurrentNodeRemoval() throws Exception
{
1.18 +5 -4 JBossCache/tests/functional/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NodeInterceptorRemoveNodeTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- NodeInterceptorRemoveNodeTest.java 7 Feb 2007 22:06:50 -0000 1.17
+++ NodeInterceptorRemoveNodeTest.java 7 Mar 2007 18:00:51 -0000 1.18
@@ -136,8 +136,9 @@
assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(false, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- assertEquals(0, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().size());
+ assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(1).size());
assertEquals(null, workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("/two")));
+ System.out.println(entry.getModifications());
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
@@ -176,7 +177,7 @@
assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().size());
+ assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(0).size());
assertNotNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
assertEquals(null, workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("/one")));
assertEquals(2, entry.getModifications().size());
@@ -407,7 +408,7 @@
WorkspaceNode one = workspace.getNode(Fqn.fromString("/one"));
- assertEquals(1, one.getMergedChildren().size());
+ assertEquals(1, one.getMergedChildren().get(0).size());
cache.remove("/one/two");
@@ -425,7 +426,7 @@
mgr.commit();
- assertEquals(0, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().size());
+ assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(1).size());
//assert what should be the results of our call
assertEquals(3, workspace.getNodes().size());
1.1 date: 2007/03/07 18:00:51; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/optimistic/LockParentVersionTest.java
Index: LockParentVersionTest.java
===================================================================
package org.jboss.cache.optimistic;
/**
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class LockParentVersionTest extends ParentVersionTest
{
public LockParentVersionTest(String name)
{
super(name);
lockParentForChildInsertRemove = true;
}
}
1.1 date: 2007/03/07 18:00:51; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/optimistic/ParentVersionTest.java
Index: ParentVersionTest.java
===================================================================
package org.jboss.cache.optimistic;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.VersionedNode;
import javax.transaction.TransactionManager;
/**
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class ParentVersionTest extends AbstractOptimisticTestCase
{
private Cache cache;
private TransactionManager tm;
protected boolean lockParentForChildInsertRemove = false; // the default
private Fqn parent = Fqn.fromString("/parent");
private Fqn child1 = Fqn.fromString("/parent/child1");
private Fqn child2 = Fqn.fromString("/parent/child2");
private Fqn deepchild = Fqn.fromString("/parent/deep/child");
public ParentVersionTest(String name)
{
super(name);
}
protected void setUp() throws Exception
{
if (lockParentForChildInsertRemove)
{
cache = createCacheUnstarted();
cache.getConfiguration().setLockParentForChildInsertRemove(true);
cache.start();
}
else
cache = createCache();
tm = ((CacheSPI) cache).getTransactionManager();
}
protected void tearDown()
{
destroyCache(cache);
}
private long getVersion(Node n)
{
return ((DefaultDataVersion) ((VersionedNode) n).getVersion()).getRawVersion();
}
public void testSimpleAdd()
{
cache.put(parent, "k", "v");
long parentVersion = getVersion(cache.getRoot().getChild(parent));
cache.put(child1, "k", "v");
if (lockParentForChildInsertRemove)
assertEquals(parentVersion + 1, getVersion(cache.getRoot().getChild(parent)));
else
assertEquals(parentVersion, getVersion(cache.getRoot().getChild(parent)));
assertTrue(cache.getRoot().hasChild(parent));
assertTrue(cache.getRoot().hasChild(child1));
}
public void testSimpleRemove()
{
cache.put(parent, "k", "v");
cache.put(child1, "k", "v");
assertTrue(cache.getRoot().hasChild(parent));
assertTrue(cache.getRoot().hasChild(child1));
long parentVersion = getVersion(cache.getRoot().getChild(parent));
cache.removeNode(child1);
if (lockParentForChildInsertRemove)
assertEquals(parentVersion + 1, getVersion(cache.getRoot().getChild(parent)));
else
assertEquals(parentVersion, getVersion(cache.getRoot().getChild(parent)));
assertTrue(cache.getRoot().hasChild(parent));
assertFalse("Should have removed child1", cache.getRoot().hasChild(child1));
}
public void testAddAndRemove() throws Exception
{
cache.put(parent, "k", "v");
cache.put(child1, "k", "v");
assertTrue(cache.getRoot().hasChild(parent));
assertTrue(cache.getRoot().hasChild(child1));
assertFalse(cache.getRoot().hasChild(child2));
long parentVersion = getVersion(cache.getRoot().getChild(parent));
tm.begin();
cache.put(child2, "k", "v");
cache.removeNode(child1);
tm.commit();
if (lockParentForChildInsertRemove)
assertEquals(parentVersion + 1, getVersion(cache.getRoot().getChild(parent)));
else
assertEquals(parentVersion, getVersion(cache.getRoot().getChild(parent)));
assertTrue(cache.getRoot().hasChild(parent));
assertFalse("Should have removed child1", cache.getRoot().hasChild(child1));
assertTrue(cache.getRoot().hasChild(child2));
}
public void testAddAndRemoveOverlap() throws Exception
{
cache.put(parent, "k", "v");
cache.put(child1, "k", "v");
assertTrue(cache.getRoot().hasChild(parent));
assertTrue(cache.getRoot().hasChild(child1));
assertFalse(cache.getRoot().hasChild(child2));
long parentVersion = getVersion(cache.getRoot().getChild(parent));
tm.begin();
cache.put(child2, "k", "v");
cache.removeNode(child1);
cache.removeNode(child2);
cache.removeNode(child1);
cache.put(child1, "k", "v");
cache.removeNode(child1);
cache.removeNode(child2);
cache.put(child2, "k", "v");
tm.commit();
if (lockParentForChildInsertRemove)
assertEquals(parentVersion + 1, getVersion(cache.getRoot().getChild(parent)));
else
assertEquals(parentVersion, getVersion(cache.getRoot().getChild(parent)));
assertTrue(cache.getRoot().hasChild(parent));
assertFalse("Should have removed child1", cache.getRoot().hasChild(child1));
assertTrue(cache.getRoot().hasChild(child2));
}
public void testRemoveAndAdd() throws Exception
{
cache.put(parent, "k", "v");
cache.put(child1, "k", "v");
assertTrue(cache.getRoot().hasChild(parent));
assertTrue(cache.getRoot().hasChild(child1));
assertFalse(cache.getRoot().hasChild(child2));
long parentVersion = getVersion(cache.getRoot().getChild(parent));
tm.begin();
cache.removeNode(child1);
cache.put(child2, "k", "v");
tm.commit();
if (lockParentForChildInsertRemove)
assertEquals(parentVersion + 1, getVersion(cache.getRoot().getChild(parent)));
else
assertEquals(parentVersion, getVersion(cache.getRoot().getChild(parent)));
assertTrue(cache.getRoot().hasChild(parent));
assertFalse("Should have removed child1", cache.getRoot().hasChild(child1));
assertTrue(cache.getRoot().hasChild(child2));
}
public void testDeepRemove()
{
cache.put(parent, "k", "v");
cache.put(deepchild, "k", "v");
assertTrue(cache.getRoot().hasChild(parent));
assertTrue(cache.getRoot().hasChild(deepchild));
long parentVersion = getVersion(cache.getRoot().getChild(parent));
cache.removeNode(deepchild);
assertEquals(parentVersion, getVersion(cache.getRoot().getChild(parent)));
assertTrue(cache.getRoot().hasChild(parent));
assertFalse("Should have removed deepchild", cache.getRoot().hasChild(deepchild));
}
public void testDeepAdd()
{
cache.put(parent, "k", "v");
assertTrue(cache.getRoot().hasChild(parent));
assertFalse(cache.getRoot().hasChild(deepchild));
long parentVersion = getVersion(cache.getRoot().getChild(parent));
cache.put(deepchild, "k", "v");
if (lockParentForChildInsertRemove)
assertEquals(parentVersion + 1, getVersion(cache.getRoot().getChild(parent)));
else
assertEquals(parentVersion, getVersion(cache.getRoot().getChild(parent)));
assertTrue(cache.getRoot().hasChild(parent));
assertTrue(cache.getRoot().hasChild(deepchild));
}
}
More information about the jboss-cvs-commits
mailing list