Author: bstansberry(a)jboss.com
Date: 2007-12-22 12:04:39 -0500 (Sat, 22 Dec 2007)
New Revision: 4916
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
Log:
[JBCACHE-1251] Test showing the issue
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-12-21
17:11:56 UTC (rev 4915)
+++
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-12-22
17:04:39 UTC (rev 4916)
@@ -459,6 +459,81 @@
assertEquals(null, cache1.get(fqn, "key"));
}
+ /**
+ * Test for JBCACHE-1251.
+ *
+ * @throws Exception
+ */
+ public void testPessimisticNodeResurrection2() throws Exception
+ {
+ nodeResurrectionTest2(false);
+ }
+
+ /**
+ * OPTIMISTIC locking verion of test for JBCACHE-1251. JBCACHE-1251
+ * did not effect optimistic, but we add the test to guard against
+ * regressions.
+ *
+ * @throws Exception
+ */
+ public void testOptimisticNodeResurrection2() throws Exception
+ {
+ nodeResurrectionTest2(true);
+ }
+
+ /**
+ * Here we model a scenario where a parent node represents
+ * a structural node, and then child nodes represent different
+ * data elements.
+ *
+ * Such data structures are set up on both caches, and then the parent node
+ * is removed (globally) and re-added (locally) on one cache. This
+ * represents an attempt to clear the region -- removing a node and
+ * re-adding is one of the only ways to do this.
+ *
+ * On the second cache, the fact that the structural node is missing is
+ * detected, and an attempt is made to re-add it locally.
+ *
+ * @param optimistic should the cache be configured for optimistic locking
+ * @throws Exception
+ */
+ private void nodeResurrectionTest2(boolean optimistic) throws Exception
+ {
+ 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);
+ assertEquals(true, root1.hasChild(fqn));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(fqn);
+ assertEquals(true, root1.hasChild(fqn));
+
+ Fqn<String> child = new Fqn(fqn, "child");
+ cache1.putForExternalRead(child, "key", "value");
+ cache2.putForExternalRead(child, "key", "value");
+ assertEquals("value", cache1.get(child, "key"));
+ assertEquals("value", cache2.get(child, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(fqn);
+ assertEquals(true, root1.hasChild(fqn));
+
+ Node remoteNode = root2.getChild(fqn);
+ checkRemoteNodeIsRemoved(remoteNode);
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root2.addChild(fqn);
+ assertEquals(true, root2.hasChild(fqn));
+ }
+
private void dumpVersionInfo(CacheSPI c1, CacheSPI c2, Fqn fqn)
{
System.out.println("**** Versin Info for Fqn [" + fqn + "]
****");
Show replies by date