[jbosscache-commits] JBoss Cache SVN: r7734 - in core/branches/3.0.X/src: test/java/org/jboss/cache/api and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Feb 19 08:23:09 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-02-19 08:23:08 -0500 (Thu, 19 Feb 2009)
New Revision: 7734

Modified:
   core/branches/3.0.X/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
   core/branches/3.0.X/src/test/java/org/jboss/cache/api/ReAddDeletedNodeTest.java
Log:
JBCACHE-1481 -  Re-adding a node deleted via parent inside transaction breaks the parent - improved the test and the fix

Modified: core/branches/3.0.X/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java
===================================================================
--- core/branches/3.0.X/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java	2009-02-19 13:21:22 UTC (rev 7733)
+++ core/branches/3.0.X/src/main/java/org/jboss/cache/mvcc/MVCCNodeHelper.java	2009-02-19 13:23:08 UTC (rev 7734)
@@ -86,9 +86,9 @@
     * nodes already exist in the context then the node is not wrapped again.
     * <p/>
     * {@link InternalNode}s are wrapped using {@link org.jboss.cache.NodeFactory#createWrappedNode(org.jboss.cache.InternalNode,
-    * org.jboss.cache.InternalNode)} and as such, null internal nodes are treated according to isolation level used.
-    * See {@link org.jboss.cache.NodeFactory#createWrappedNode(org.jboss.cache.InternalNode,
-    * org.jboss.cache.InternalNode)} for details on this behaviour.
+    * org.jboss.cache.InternalNode)} and as such, null internal nodes are treated according to isolation level used. See
+    * {@link org.jboss.cache.NodeFactory#createWrappedNode(org.jboss.cache.InternalNode, org.jboss.cache.InternalNode)}
+    * for details on this behaviour.
     * <p/>
     * Note that if the context has the {@link org.jboss.cache.config.Option#isForceWriteLock()} option set, then write
     * locks are acquired and the node is copied.
@@ -197,6 +197,7 @@
             if (trace) log.trace("Node is deleted in current scope.  Need to un-delete.");
             n.markAsDeleted(false);
             n.setValid(true, false);
+            n.clearData(); // a delete and re-add should flush any old state on the node!
             // has the parent been deleted too?  :-(
             wrapNodeForWriting(context, fqn.getParent(), true, true, includeInvalidNodes, false, force);
          }

Modified: core/branches/3.0.X/src/test/java/org/jboss/cache/api/ReAddDeletedNodeTest.java
===================================================================
--- core/branches/3.0.X/src/test/java/org/jboss/cache/api/ReAddDeletedNodeTest.java	2009-02-19 13:21:22 UTC (rev 7733)
+++ core/branches/3.0.X/src/test/java/org/jboss/cache/api/ReAddDeletedNodeTest.java	2009-02-19 13:23:08 UTC (rev 7734)
@@ -37,4 +37,49 @@
       assert cache.getNode(testFqn.getParent()) != null : testFqn.getParent() + " should not be null (after commit)";
       assert cache.getNode(testFqn.getParent().getParent()) != null : testFqn.getParent().getParent() + " should not be null (after commit)";
    }
+
+   public void testReAddWithData() throws Exception {
+      TransactionManager tm = cache.getTransactionManager();
+      Fqn<String> testFqn = Fqn.fromElements("a", "a", "a");
+
+      tm.begin();
+      cache.put(testFqn, "1", "2");
+      assert cache.get(testFqn, "1").equals("2");
+      assert cache.get(testFqn, "3") == null;
+      cache.removeNode(testFqn.getParent());
+      cache.put(testFqn, "3", "4");
+      assert cache.get(testFqn, "3").equals("4");
+      assert cache.get(testFqn, "1") == null;
+      assert cache.getNode(testFqn) != null : testFqn + " should not be null (before commit)";
+      assert cache.getNode(testFqn.getParent()) != null : testFqn.getParent() + " should not be null (before commit)";
+      assert cache.getNode(testFqn.getParent().getParent()) != null : testFqn.getParent().getParent() + " should not be null (before commit)";
+      tm.commit();
+      assert cache.getNode(testFqn) != null : testFqn + " should not be null (after commit)";
+      assert cache.getNode(testFqn.getParent()) != null : testFqn.getParent() + " should not be null (after commit)";
+      assert cache.getNode(testFqn.getParent().getParent()) != null : testFqn.getParent().getParent() + " should not be null (after commit)";
+   }
+
+   public void testReAddWithDataOnParent() throws Exception {
+      TransactionManager tm = cache.getTransactionManager();
+      Fqn<String> testFqn = Fqn.fromElements("a", "a", "a");
+
+      tm.begin();
+      cache.put(testFqn, "x", "x");
+      cache.put(testFqn.getParent(), "parent_x", "parent_x");
+      assert cache.get(testFqn, "x").equals("x");
+      assert cache.get(testFqn.getParent(), "parent_x").equals("parent_x");
+      cache.removeNode(testFqn.getParent());
+      cache.put(testFqn, "y", "y");
+      assert cache.get(testFqn, "y").equals("y");
+      assert cache.get(testFqn.getParent(), "parent_x") == null;
+      assert cache.getNode(testFqn.getParent()).getData().isEmpty();
+      assert cache.getNode(testFqn) != null : testFqn + " should not be null (before commit)";
+      assert cache.getNode(testFqn.getParent()) != null : testFqn.getParent() + " should not be null (before commit)";
+      assert cache.getNode(testFqn.getParent().getParent()) != null : testFqn.getParent().getParent() + " should not be null (before commit)";
+      tm.commit();
+      assert cache.getNode(testFqn) != null : testFqn + " should not be null (after commit)";
+      assert cache.getNode(testFqn.getParent()) != null : testFqn.getParent() + " should not be null (after commit)";
+      assert cache.getNode(testFqn.getParent().getParent()) != null : testFqn.getParent().getParent() + " should not be null (after commit)";
+   }
+
 }




More information about the jbosscache-commits mailing list