jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r825772 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java test/java/org/apache/jackrabbit/core/XATest.java
Date Fri, 16 Oct 2009 05:37:11 GMT
Author: ckoell
Date: Fri Oct 16 05:37:11 2009
New Revision: 825772

URL: http://svn.apache.org/viewvc?rev=825772&view=rev
Log:
JCR-2356 Session holds LockToken after removeLockToken in XA Environment

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java?rev=825772&r1=825771&r2=825772&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/XAEnvironment.java
Fri Oct 16 05:37:11 2009
@@ -485,6 +485,8 @@
                 LockInfo xaEnvLock = getLockInfo(node);
                 // Check if the lockToken has been removed in the transaction ...
                 if (xaEnvLock != null && xaEnvLock.getLockHolder() == null) {
+                    //Remove lockToken from SessionLockManager
+                    getSessionLockManager(internalLock.getLockHolder()).lockTokenRemoved(internalLock.getLockToken());
                     internalLock.setLockHolder(null);
                 }
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java?rev=825772&r1=825771&r2=825772&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java
Fri Oct 16 05:37:11 2009
@@ -828,6 +828,79 @@
             other.logout();
         }
     }
+    
+    /**
+     * Test locking and unlocking behavior in transaction
+     * (see JCR-2356)
+     * @throws Exception
+     */
+    public void testCreateLockUnlockInDifferentTransactions() throws Exception {
+        // create new node and lock it
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        utx.begin();
+
+        // add node that is both lockable and referenceable, save
+        Node rootNode = superuser.getRootNode(); 
+        Node n = rootNode.addNode(nodeName1);
+        n.addMixin(mixLockable);
+        n.addMixin(mixReferenceable);
+        rootNode.save();
+        
+        String uuid = n.getUUID();
+        
+        // commit
+        utx.commit();
+        
+        // start new Transaction and try to add lock token
+        utx = new UserTransactionImpl(superuser);
+        utx.begin();
+        
+        n = superuser.getNodeByUUID(uuid);
+        // lock this new node
+        Lock lock = n.lock(true, false);
+        
+        // verify node is locked
+        assertTrue("Node not locked", n.isLocked());
+        
+        String lockToken = lock.getLockToken();
+        // assert: session must get a non-null lock token
+        assertNotNull("session must get a non-null lock token", lockToken);
+        // assert: session must hold lock token
+        assertTrue("session must hold lock token", containsLockToken(superuser, lockToken));
+
+        n.save();
+
+        superuser.removeLockToken(lockToken);
+        assertNull("session must get a null lock token", lock.getLockToken());
+        assertFalse("session must not hold lock token", containsLockToken(superuser, lockToken));
+        
+        // commit
+        utx.commit();
+
+        assertFalse("session must not hold lock token", containsLockToken(superuser, lockToken));
+        assertNull("session must get a null lock token", lock.getLockToken());
+
+        // start new Transaction and try to unlock
+        utx = new UserTransactionImpl(superuser);
+        utx.begin();
+
+        n = superuser.getNodeByUUID(uuid);
+
+        // verify node is locked
+        assertTrue("Node not locked", n.isLocked());
+        // assert: session must not hold lock token
+        assertFalse("session must not hold lock token", containsLockToken(superuser, lockToken));
+        
+        superuser.addLockToken(lockToken);
+        
+        // assert: session must not hold lock token
+        assertTrue("session must hold lock token", containsLockToken(superuser, lockToken));
+
+        n.unlock();
+        
+        // commit
+        utx.commit();
+    }
 
     /**
      * Test locking a node in one session. Verify that node is not locked



Mime
View raw message