jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r944282 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java
Date Fri, 14 May 2010 14:23:31 GMT
Author: jukka
Date: Fri May 14 14:23:31 2010
New Revision: 944282

URL: http://svn.apache.org/viewvc?rev=944282&view=rev
Log:
JCR-2503: inconsistent session and persistent state after ReferentialIntegrityException

Added a test case based on code by Bram de Kruijff.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java?rev=944282&r1=944281&r2=944282&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NodeImplTest.java
Fri May 14 14:23:31 2010
@@ -24,6 +24,7 @@ import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.PropertyType;
+import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
@@ -33,6 +34,7 @@ import javax.jcr.security.AccessControlP
 import javax.jcr.security.Privilege;
 
 import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.slf4j.Logger;
@@ -252,4 +254,85 @@ public class NodeImplTest extends Abstra
         testRootNode.getSession().save();
         assertFalse(n2.hasProperty("jcr:uuid"));
     }
+
+
+    /**
+     * Test corruption in session / persistence state after
+     * {@link ReferentialIntegrityException}.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-2503">JCR-2503</a>
+     */
+    public void testReferentialIntegrityCorruption() throws Exception {
+        Session session = testRootNode.getSession();
+        Node root = testRootNode.addNode("testReferentialIntegrityCorruption");
+
+        // Create test nodes P1 and P2
+        Node nodeP1 = root.addNode("P1");
+        nodeP1.addMixin("mix:referenceable");
+        Node nodeP2 = root.addNode("P2");
+        nodeP2.addMixin("mix:referenceable");
+        session.save();
+
+        // Create reference from P2 to P1 and save
+        nodeP2.setProperty("referencetoP1", nodeP1);
+        session.save();
+
+        // Add node P3
+        Node nodeP3 = root.addNode("P3");
+        nodeP3.addMixin("mix:referenceable");
+
+        // And try to remove P1 while P2 still references P1
+        nodeP1.remove();
+        try {
+            session.save();
+        } catch (ReferentialIntegrityException expected) {
+            // Got ReferentialIntegrityException as expected
+        }
+
+        // Remove P2 and save again, this will succeed. As P1, P2
+        // should be removed and P3 should exist
+        try {
+            nodeP2.remove();
+            session.save();
+        } catch (Exception e) {
+            String msg =
+                "JCR-2503: Saving delete after"
+                + " ReferentialIntegrityException failed";
+            log.error(msg, e);
+            fail(msg);
+        }
+
+        try {
+            nodeP3 = session.getNodeByIdentifier(nodeP3.getIdentifier());
+        } catch (Exception e) {
+            String msg =
+                "JCR-2503: Retrieving P3 by uuid failed. Corrupt session?";
+            log.error(msg, e);
+            fail(msg);
+        }
+
+        try {
+            nodeP3.remove();
+            session.save();
+        } catch (Exception e) {
+            String msg = "JCR-2503: Removing P3 failed. Corrupt session?";
+            log.error(msg, e);
+            fail(msg);
+        }
+
+        try {
+            root = testRootNode.getNode("testReferentialIntegrityCorruption");
+            for (@SuppressWarnings("unused") Node ignore
+                    : JcrUtils.getChildNodes(root)) {
+            }
+        } catch (Exception e) {
+            String msg = "JCR-2503: Failed to scan empty node. Corrupt session?";
+            log.error(msg, e);
+            fail(msg);
+        }
+
+        root.remove();
+        session.save();
+    }
+
 }



Mime
View raw message