jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r354456 [2/2] - in /incubator/jackrabbit/trunk/jackrabbit/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/lock/ main/java/org/apache/jackrabbit/core/state/ main/java/org/apache/jackrabbit/core/xml/ test/java/...
Date Tue, 06 Dec 2005 16:08:43 GMT
Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java?rev=354456&r1=354455&r2=354456&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
Tue Dec  6 08:07:53 2005
@@ -113,7 +113,7 @@
 
         SessionImpl ses = (SessionImpl) wsp.getSession();
         itemOps = new BatchedItemOperations(wsp.getItemStateManager(),
-                ntReg, wsp.getLockManager(), ses, wsp.getHierarchyManager(),
+                ntReg, ses.getLockManager(), ses, wsp.getHierarchyManager(),
                 ses.getNamespaceResolver());
         hierMgr = wsp.getHierarchyManager();
 

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/UserTransactionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/UserTransactionImpl.java?rev=354456&r1=354455&r2=354456&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/UserTransactionImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/UserTransactionImpl.java
Tue Dec  6 08:07:53 2005
@@ -31,7 +31,7 @@
 /**
  * Internal {@link javax.transaction.UserTransaction} implementation.
  */
-class UserTransactionImpl implements UserTransaction {
+public class UserTransactionImpl implements UserTransaction {
 
     /**
      * Global transaction id counter

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/XATest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/XATest.java?rev=354456&r1=354455&r2=354456&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/XATest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/core/XATest.java
Tue Dec  6 08:07:53 2005
@@ -555,4 +555,191 @@
         // logout
         otherSuperuser.logout();
     }
+
+    /**
+     * Test locking a node in one session. Verify that node is not locked
+     * in other session until commit.
+     * @throws Exception
+     */
+    public void testLockCommit() throws Exception {
+        Session other = helper.getSuperuserSession();
+
+        // add node that is both lockable and referenceable, save
+        Node n = testRootNode.addNode(nodeName1);
+        n.addMixin(mixLockable);
+        n.addMixin(mixReferenceable);
+        testRootNode.save();
+
+        // reference node in second session
+        Node nOther = other.getNodeByUUID(n.getUUID());
+
+        // verify node is not locked in either session
+        assertFalse("Node not locked in session 1", n.isLocked());
+        assertFalse("Node not locked in session 2", nOther.isLocked());
+
+        // get user transaction object, start and lock node
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        utx.begin();
+        n.lock(false, true);
+
+        // verify node is locked in first session only
+        assertTrue("Node locked in session 1", n.isLocked());
+        assertFalse("Node not locked in session 2", nOther.isLocked());
+
+        // commit in first session
+        utx.commit();
+
+        // verify node is locked in both sessions
+        assertTrue("Node locked in session 1", n.isLocked());
+        assertTrue("Node locked in session 2", nOther.isLocked());
+
+        // logout
+        other.logout();
+    }
+
+    /**
+     * Test locking a node in one session. Verify that node is not locked
+     * in session after rollback.
+     * @throws Exception
+     */
+    public void testLockRollback() throws Exception {
+        Session other = helper.getSuperuserSession();
+
+        // add node that is both lockable and referenceable, save
+        Node n = testRootNode.addNode(nodeName1);
+        n.addMixin(mixLockable);
+        n.addMixin(mixReferenceable);
+        testRootNode.save();
+
+        // reference node in second session
+        Node nOther = other.getNodeByUUID(n.getUUID());
+
+        // verify node is not locked in either session
+        assertFalse("Node not locked in session 1", n.isLocked());
+        assertFalse("Node not locked in session 2", nOther.isLocked());
+
+        // get user transaction object, start and lock node
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        utx.begin();
+        n.lock(false, true);
+
+        // verify node is locked in first session only
+        assertTrue("Node locked in session 1", n.isLocked());
+        assertFalse("Node not locked in session 2", nOther.isLocked());
+
+        // rollback in first session
+        utx.rollback();
+
+        // verify node is not locked in either session
+        assertFalse("Node not locked in session 1", n.isLocked());
+        assertFalse("Node not locked in session 2", nOther.isLocked());
+
+        // logout
+        other.logout();
+    }
+
+    /**
+     * Test locking a node inside a transaction that has been locked in another
+     * session, which leads to a failure when committing.
+     * @throws Exception
+     */
+    public void testLockTwice() throws Exception {
+        Session other = helper.getSuperuserSession();
+
+        // add node that is both lockable and referenceable, save
+        Node n = testRootNode.addNode(nodeName1);
+        n.addMixin(mixLockable);
+        n.addMixin(mixReferenceable);
+        testRootNode.save();
+
+        // reference node in second session
+        Node nOther = other.getNodeByUUID(n.getUUID());
+
+        // verify node is not locked in either session
+        assertFalse("Node not locked in session 1", n.isLocked());
+        assertFalse("Node not locked in session 2", nOther.isLocked());
+
+        // get user transaction object, start and lock node
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        utx.begin();
+        n.lock(false, true);
+
+        // lock node in non-transactional session, too
+        nOther.lock(false, true);
+
+        // verify node is locked in both sessions
+        assertTrue("Node locked in session 1", n.isLocked());
+        assertTrue("Node locked in session 2", nOther.isLocked());
+
+        // assertion: commit must fail since node has already been locked
+        try {
+            utx.commit();
+            fail("Commit succeeds with double locking");
+        } catch (RollbackException e) {
+            /* expected */
+        }
+
+        // verify node is locked in both sessions
+        assertTrue("Node locked in session 1", n.isLocked());
+        assertTrue("Node locked in session 2", nOther.isLocked());
+
+        // logout
+        other.logout();
+    }
+
+    /**
+     * Test locking a new node inside a transaction.
+     * @throws Exception
+     */
+    public void testLockNewNode() throws Exception {
+        // get user transaction object, start
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        utx.begin();
+
+        // add node that is both lockable and referenceable, save
+        Node n = testRootNode.addNode(nodeName1);
+        n.addMixin(mixLockable);
+        n.addMixin(mixReferenceable);
+        testRootNode.save();
+
+        // lock this new node
+        n.lock(false, true);
+
+        // commit
+        utx.commit();
+    }
+
+    /**
+     * Test locking/unlocking a node inside a transaction which should be a
+     * no-op.
+     * @throws Exception
+     */
+    public void testLockUnlock() throws Exception {
+        // add node that is both lockable and referenceable, save
+        Node n = testRootNode.addNode(nodeName1);
+        n.addMixin(mixLockable);
+        n.addMixin(mixReferenceable);
+        testRootNode.save();
+
+        // verify node is not locked in this session
+        assertFalse("Node not locked", n.isLocked());
+
+        // get user transaction object, start and lock node
+        UserTransaction utx = new UserTransactionImpl(superuser);
+        utx.begin();
+        n.lock(false, true);
+
+        // verify node is locked
+        assertTrue("Node locked", n.isLocked());
+
+        // unlock node
+        n.unlock();
+
+        // commit
+        utx.commit();
+
+        // verify node is not locked
+        assertFalse("Node not locked", n.isLocked());
+    }
+
 }



Mime
View raw message