jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r719575 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/NodeImpl.java test/java/org/apache/jackrabbit/api/jsr283/lock/AbstractLockTest.java
Date Fri, 21 Nov 2008 13:23:42 GMT
Author: angela
Date: Fri Nov 21 05:23:42 2008
New Revision: 719575

URL: http://svn.apache.org/viewvc?rev=719575&view=rev
Log:
JCR-1868: Inconsistent state when removing mix:lockable from a locked Node

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/lock/AbstractLockTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=719575&r1=719574&r2=719575&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Fri Nov 21 05:23:42 2008
@@ -1168,6 +1168,18 @@
             }
         }
 
+        /*
+         * mix:lockable: the mixin cannot be removed if the node is currently
+         * locked even if the editing session is the lock holder.
+         */
+        if ((NameConstants.MIX_LOCKABLE.equals(mixinName)
+                || mixin.isDerivedFrom(NameConstants.MIX_LOCKABLE))
+                && !entRemaining.includesNodeType(NameConstants.MIX_LOCKABLE)
+                && isLocked()) {
+            throw new ConstraintViolationException(mixinName + " can not be removed: the
node is locked.");
+        }
+
+
         // modify the state of this node
         NodeState thisState = (NodeState) getOrCreateTransientItemState();
         thisState.setMixinTypeNames(remainingMixins);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/lock/AbstractLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/lock/AbstractLockTest.java?rev=719575&r1=719574&r2=719575&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/lock/AbstractLockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/lock/AbstractLockTest.java
Fri Nov 21 05:23:42 2008
@@ -19,12 +19,13 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.jackrabbit.test.AbstractJCRTest;
-import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.Node;
 import javax.jcr.Session;
 import javax.jcr.RepositoryException;
-import javax.jcr.lock.*;
+import javax.jcr.nodetype.ConstraintViolationException;
+import java.util.List;
+import java.util.Arrays;
 
 /** <code>AbstractLockTest</code>... */
 public abstract class AbstractLockTest extends AbstractJCRTest {
@@ -90,6 +91,14 @@
         } finally {
             otherSession.logout();
         }
+
+        Session otherAdmin = helper.getSuperuserSession();
+        try {
+            Lock lck = (Lock) ((Node) otherAdmin.getItem(lockedNode.getPath())).getLock();
+            assertFalse("Other Session for the same userID must not be lock owner", lck.isLockOwningSession());
+        } finally {
+            otherAdmin.logout();
+        }
     }
 
     /**
@@ -98,4 +107,42 @@
     public void testGetSecondsRemaining() {
         assertTrue("Seconds remaining must be a positive long or 0.", lock.getSecondsRemaining()
>= 0);
     }
+
+
+
+
+    public void testRemoveMixLockableFromLockedNode() throws RepositoryException {
+        try {
+            lockedNode.removeMixin(mixLockable);
+            lockedNode.save();
+
+            // the mixin got removed -> the lock should implicitely be released
+            // as well in order not to have inconsistencies
+            String msg = "Lock should have been released.";
+            assertFalse(msg, lock.isLive());
+            assertFalse(msg, lockedNode.isLocked());
+            List tokens = Arrays.asList(superuser.getLockTokens());
+            assertFalse(msg, tokens.contains(lock.getLockToken()));
+
+            assertFalse(msg, lockedNode.hasProperty(jcrLockOwner));
+            assertFalse(msg, lockedNode.hasProperty(jcrlockIsDeep));
+
+        } catch (ConstraintViolationException e) {
+            // cannot remove the mixin -> ok
+            // consequently the node must still be locked, the lock still live...
+            String msg = "Lock must still be live.";
+            assertTrue(msg, lock.isLive());
+            assertTrue(msg, lockedNode.isLocked());
+            List tokens = Arrays.asList(superuser.getLockTokens());
+            assertTrue(tokens.contains(lock.getLockToken()));
+            assertTrue(msg, lockedNode.hasProperty(jcrLockOwner));
+            assertTrue(msg, lockedNode.hasProperty(jcrlockIsDeep));
+        } finally {
+            // ev. re-add the mixin in order to be able to unlock the node
+            if (lockedNode.isLocked() && !lockedNode.isNodeType(mixLockable)) {
+                lockedNode.addMixin(mixLockable);
+                lockedNode.save();
+            }
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message