[jbosscache-commits] JBoss Cache SVN: r4632 - core/trunk/src/test/java/org/jboss/cache/invalidation.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Wed Oct 17 11:25:57 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-10-17 11:25:57 -0400 (Wed, 17 Oct 2007)
New Revision: 4632
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
Log:
Add tests of node removal
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 14:58:56 UTC (rev 4631)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 15:25:57 UTC (rev 4632)
@@ -22,7 +22,11 @@
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -382,6 +386,89 @@
cache2 = null;
}
+ public void testPessimisticNodeRemoval() throws Exception
+ {
+ nodeRemovalTest(false);
+ }
+
+ public void testOptimisticNodeRemoval() throws Exception
+ {
+ nodeRemovalTest(true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void nodeRemovalTest(boolean optimistic) throws Exception
+ {
+ CacheImpl<Object, Object> cache1 = null;
+ CacheImpl<Object, Object> cache2 = null;
+ try
+ {
+ cache1 = createCache(optimistic);
+ cache2 = createCache(optimistic);
+
+ Node root1 = cache1.getRoot();
+ Node root2 = cache2.getRoot();
+
+ // this fqn is relative, but since it is from the root it may as well be absolute
+ Fqn<String> fqn = Fqn.fromString("/test/fqn");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(fqn);
+ assertTrue(root1.hasChild(fqn));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root2.addChild(fqn);
+ assertTrue(root2.hasChild(fqn));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+ Node remoteNode = root2.getChild(fqn);
+ checkRemoteNodeIsRemoved(remoteNode);
+ assertEquals(false, cache1.removeNode(fqn));
+
+ Fqn<String> child = Fqn.fromString("/test/fqn/child");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(child);
+ assertTrue(root1.hasChild(child));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root2.addChild(child);
+ assertTrue(root2.hasChild(child));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+ remoteNode = root2.getChild(fqn);
+ checkRemoteNodeIsRemoved(remoteNode);
+ assertEquals(false, cache1.removeNode(fqn));
+ }
+ finally
+ {
+ if (cache1 != null)
+ {
+ cache1.stop();
+ cache1.destroy();
+ }
+ if (cache2 != null)
+ {
+ cache2.stop();
+ cache2.destroy();
+ }
+
+ }
+
+ }
+
+ private void checkRemoteNodeIsRemoved(Node<Object, Object> remoteNode) {
+
+ assertNotNull("remoteNode " + remoteNode.getFqn() +" is not null", remoteNode);
+ // FIXME A simple isValid() check should suffice,
+ // but that's not implemented
+ //assertFalse("remoteNode is not valid", remoteNode.isValid());
+ assertEquals("remoteNode " + remoteNode.getFqn() +" has no keys", 0, remoteNode.getKeys().size());
+ // Recursively check any children
+ for (Node<Object, Object> child : remoteNode.getChildren())
+ {
+ checkRemoteNodeIsRemoved(child);
+ }
+ }
+
private void dumpVersionInfo(CacheSPI c1, CacheSPI c2, Fqn fqn)
{
System.out.println("**** Versin Info for Fqn ["+fqn+"] ****");
More information about the jbosscache-commits
mailing list